An electronics shop has announced the following seasonal discounts on the purchase of certain
items.
Purchase Amount Discount on Laptop Discount on Desktop PC
0 – 250 0.0% 5.0%
251 – 570 5.0% 7.6%
571 – 1000 7.5% 10.0%
More than 1000 10.0% 15.0%
Write a program based on the above criteria to input name, address, amount of purchase and
type of purchase (L for Laptop and D for Desktop) by a customer. Compute and print the net
amount to be paid by a customer along with his name and address.
discount = (discount rate/100)* amount of purchase
Net amount = amount of purchase – discount
package Assignment;
import java.util.Scanner;
public class Assignment
{
public static void main(String[] args) throws Exception
{
String name;
String address;
int amount;
char type;
int net = 0;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter Name : ");
name = keyboard.nextLine();
System.out.print("Enter Address : ");
address = keyboard.nextLine();
System.out.print("Enter Amount of purchase : ");
amount = keyboard.nextInt();
System.out.print("Enter type of purchase : ");
type = (char)System.in.read();
System.in.read();
while(type != 'D' && type!= 'L')
{
System.out.println("Invaild type of purchase");
System.out.print("Enter type of purchase : ");
type = (char)System.in.read();
System.in.read();
}
if(amount<=250)
{
if(type == 'D')
{
net = ((95/100)*amount);
System.out.println("net price : " +net);
}
else if(type == 'L')
{
net = amount;
}
}
{
System.out.println("Name : " +name);
System.out.println("Address : " +address);
System.out.println("Net price : " +amount);
System.out.println("Type of purchase : " +type);
}
}
}
output
run:
Enter Name : ffdhfjf
Enter Address : gstgdgd 435454
Enter Amount of purchase : 200
Enter type of purchase : D
net price : 0
Name : ffdhfjf
Address : gstgdgd 435454
Net price : 200
Type of purchase : D
BUILD SUCCESSFUL (total time: 24 seconds)
Why is my IF part not being able to calculate if my type is D?
items.
Purchase Amount Discount on Laptop Discount on Desktop PC
0 – 250 0.0% 5.0%
251 – 570 5.0% 7.6%
571 – 1000 7.5% 10.0%
More than 1000 10.0% 15.0%
Write a program based on the above criteria to input name, address, amount of purchase and
type of purchase (L for Laptop and D for Desktop) by a customer. Compute and print the net
amount to be paid by a customer along with his name and address.
discount = (discount rate/100)* amount of purchase
Net amount = amount of purchase – discount
package Assignment;
import java.util.Scanner;
public class Assignment
{
public static void main(String[] args) throws Exception
{
String name;
String address;
int amount;
char type;
int net = 0;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter Name : ");
name = keyboard.nextLine();
System.out.print("Enter Address : ");
address = keyboard.nextLine();
System.out.print("Enter Amount of purchase : ");
amount = keyboard.nextInt();
System.out.print("Enter type of purchase : ");
type = (char)System.in.read();
System.in.read();
while(type != 'D' && type!= 'L')
{
System.out.println("Invaild type of purchase");
System.out.print("Enter type of purchase : ");
type = (char)System.in.read();
System.in.read();
}
if(amount<=250)
{
if(type == 'D')
{
net = ((95/100)*amount);
System.out.println("net price : " +net);
}
else if(type == 'L')
{
net = amount;
}
}
{
System.out.println("Name : " +name);
System.out.println("Address : " +address);
System.out.println("Net price : " +amount);
System.out.println("Type of purchase : " +type);
}
}
}
output
run:
Enter Name : ffdhfjf
Enter Address : gstgdgd 435454
Enter Amount of purchase : 200
Enter type of purchase : D
net price : 0
Name : ffdhfjf
Address : gstgdgd 435454
Net price : 200
Type of purchase : D
BUILD SUCCESSFUL (total time: 24 seconds)
Why is my IF part not being able to calculate if my type is D?