Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Internet Delicatessen

 
Jeffrey Samuel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a problem with this code. There are no errors but when I enter the item, tuna fish. It says InputMismatchException.

Here is the code I have so far.



Here is the question.

Sam and Ella's Delicatessen wants you to write a program to take orders from the Internet. Your program asks for the item, its price, and if overnight shipping is wanted. Regular shipping for items under $10 is $2.00; for items $10 or more shipping is $3.00. For overnight delivery add $5.00.

Enter the item:
Tuna Salad
Enter the price:
450
Overnight delivery (0==no, 1==yes)
1

Invoice:
Tuna Salad 4.50
shipping 7.00
total 11.50
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are declaring item as an integer, when I think you really want a string.

-Hunter
 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should not capitalize your variable names.....

And your statement for overnight delivery does not match the spec requirements.

Janeice
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And when you get to printing, you will get many many outputs.
Have you been taught to put so much in the main method? That isn't object-oriented programming.
Why are you asking whether overnight < 0? Why are you getting overnight as a number at all?
 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Why are you asking whether overnight < 0? Why are you getting overnight as a number at all?


I couldn't figure out why either.... but it looks like it's part of the spec. 0 is no, 1 is yes. A very binary setup.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't say "enter 0 for yes or 1 for no" or anything similar. It looks a bit like C code where you use 1 for true and 0 for false. It also looks like an out-by-one error because the way it is written it will take 0 or 1 both as "no".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic