HI, Need Some help on Java Coding.
I am trying to write a program to prompt user for detail price and type
then check the type to calculate the discount
but i am having error, no matter what amount i try to key in
it only show me the 1st output which is the discount from the range of 0 to 250
can anyone assist me to figure out where might be the problem from the coding ?
package testing;
import java.util.Scanner;
public class test1
{
public static void main(String[] args) throws Exception
{
String Name, Address;
int Amount;
double Net, Discount;
char type;
Scanner keyboard = new Scanner(System.in);
System.out.print("Please enter the Name : ");
Name = keyboard.next();
System.out.print("Please enter the Address : ");
Address = keyboard.next();
System.out.print("Please enter the Amount : ");
Amount = keyboard.nextInt();
System.out.print("Please enter the Type : ");
type = (char)System.in.read();
System.in.read();
if(type == 'D' || type == 'd')
{
if(Amount >= 0 || Amount <= 250)
{
Discount =(Amount/100)*5;
Net = Amount - Discount;
System.out.println("Customer Name : " +Name);
System.out.println("Net Amount : " +Net);
}
else if(Amount >= 251 || Amount <= 570)
{
Discount = (7.6/100)*Amount ;
Net = Amount - Discount;
System.out.println("Customer Name : " +Name);
System.out.println("Net Amount : " +Net);
}
else if(Amount >= 571 || Amount <= 1000)
{
Discount = (Amount/100)*10;
Net = Amount - Discount;
System.out.println("Customer Name : " +Name);
System.out.println("Net Amount : " +Net);
}
else
{
Discount = (Amount/100)*15;
Net = Amount - Discount;
System.out.println("Customer Name : " +Name);
System.out.println("Net Amount : " +Net);
}
}
}
}
I am trying to write a program to prompt user for detail price and type
then check the type to calculate the discount
but i am having error, no matter what amount i try to key in
it only show me the 1st output which is the discount from the range of 0 to 250
can anyone assist me to figure out where might be the problem from the coding ?
package testing;
import java.util.Scanner;
public class test1
{
public static void main(String[] args) throws Exception
{
String Name, Address;
int Amount;
double Net, Discount;
char type;
Scanner keyboard = new Scanner(System.in);
System.out.print("Please enter the Name : ");
Name = keyboard.next();
System.out.print("Please enter the Address : ");
Address = keyboard.next();
System.out.print("Please enter the Amount : ");
Amount = keyboard.nextInt();
System.out.print("Please enter the Type : ");
type = (char)System.in.read();
System.in.read();
if(type == 'D' || type == 'd')
{
if(Amount >= 0 || Amount <= 250)
{
Discount =(Amount/100)*5;
Net = Amount - Discount;
System.out.println("Customer Name : " +Name);
System.out.println("Net Amount : " +Net);
}
else if(Amount >= 251 || Amount <= 570)
{
Discount = (7.6/100)*Amount ;
Net = Amount - Discount;
System.out.println("Customer Name : " +Name);
System.out.println("Net Amount : " +Net);
}
else if(Amount >= 571 || Amount <= 1000)
{
Discount = (Amount/100)*10;
Net = Amount - Discount;
System.out.println("Customer Name : " +Name);
System.out.println("Net Amount : " +Net);
}
else
{
Discount = (Amount/100)*15;
Net = Amount - Discount;
System.out.println("Customer Name : " +Name);
System.out.println("Net Amount : " +Net);
}
}
}
}
