Need Help on Java Coding

SimZ909

Junior Member
Joined
Jul 11, 2014
Messages
1
Reaction score
0
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);
}
}

}

}
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
I wouldn't go further yet. Look at this expression

Code:
if (Amount >= 0 || Amount <= 250)

Could you tell me which value of Amount WILL NOT SATISFY this expression.

Then look at the rest of your codes. :)

Use a piece of paper draw a integral number line from -infinity to infinity. Mark zero and 250, draw your range line and observe your OR logical reasoning
 
Last edited:
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top