Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 if statement seeming to be ignored?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rto




PostPosted: Thu Nov 27, 2008 8:38 am   Post subject: if statement seeming to be ignored?

Java:

import java.io.*
class S8E1
{
public static void main (String [] args) throws Exception
{
InputStreamReader input = new InputStreamReader (System.in);
BufferedReader reader = new BufferedReader (input);
String itemChoice, overnightDelivery;
double itemCost, overnightDeliveryCharge, shippingCharge;
System.out.println ("Enter the item you would like to purchase");
itemChoice = reader.readLine();
System.out.println ("Enter the cost in dollars and cents (ie. $5.00 would be inputted as 5.00)");

if (itemCost <= 9.99)
{
shippingCharge = 2.00;
}
else
{
shippingCharge = 3.00;
}

System.out.println ("Would you like overnight delivery? Y or N?");
overnightDelivery = reader.readLine();

if (overnightDelivery == "Y")
{
overnightDeliveryCharge = 5.00;
}
else
{
overnightDeliveryCharge = 0.00;
}

System.out.println ("Invoice: \n " + itemChoice + " :\t\t\t" + itemCost + "\n shipping :\t\t" + shippingCharge);
System.out.print(" Overnight Deilvery :\t" + overnightDeliveryCharge + \n Total :\t\t" + ((itemCost + shippingCharge) + overnightDeliveryCharge));
 


It doesn't seem to matter if you enter Y or N in the overnight delivery section. either way it seems to ignore this part and automatically set overnightDeliveryCharge to 0.00 dollars.
Sponsor
Sponsor
Sponsor
sponsor
rto




PostPosted: Thu Nov 27, 2008 8:39 am   Post subject: RE:if statement seeming to be ignored?

and clearly that is the incorrect code .. which code do i use to post java code? :S thot it was syntax
Okapi




PostPosted: Thu Nov 27, 2008 9:22 am   Post subject: RE:if statement seeming to be ignored?

if(overnightDelivery.equals("Y")){

}

see here for more info
rto




PostPosted: Thu Dec 04, 2008 10:12 am   Post subject: RE:if statement seeming to be ignored?

thanks okapi i figured it out a while ago but forgot to mark the topic has answered Smile thanks anyways thow
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: