• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Internet Delicatessen

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are declaring item as an integer, when I think you really want a string.

-Hunter
 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79263
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79263
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
reply
    Bookmark Topic Watch Topic
  • New Topic