• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Scanners?! Where?!

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EDIT: Figured out how to properly put code into a post! Should look better now...

Hello,

I'm back with another question! It could most likely be answered by about 99% of this forum. (Maybe even 99.9%!!)

Here's my problem: I'm trying to make an application that's designed to run once and only once. The scenario is that I'm selling a product, and the program asks the customer how many of said product they want. Based on the amount given, they get a specific discount. (In this case, more than 100 in quantity gives them 50% off, 50-99 is 40%, 20-49 is 30%, 10-19 is 20%, and anything less gets no discount.)

I think I've set everything up correctly except for one main part. The user input. In C++ this equivalent would be "scanf("%i", &desiredQuantity);" or something along those lines. What would it be in Java?

Here's my code. Oh, and if you see room for improvement or other mistakes, please feel free to let me know! It's a simple program, I know. It's just practice. Because I definitely need it.


Thank you for your time!

-Nick
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is "helper" object ? And about Scanner class, look here.

And I think this discussion helps you get some things about Scannaer class.
 
Nick Garcia
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, well, basically what I'm aiming for is this: I want to ask the user to input their desired quantity, have the program store it as a variable ("quantity") then compare it to the if/else statements. I know how to do this in C++ but I can't figure it out in Java. I know it must be pretty simple. And it's probably right under my nose! I just can't seem to locate the command that would do that.
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at BufferedReader to understand the Java IO
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And.. you are using the quantity as a int but it was a String..

to make its convertation use Integer.parseInt(String str) method.




The Scanner object can read an int and make its automatically.

Something like

 
Nick Garcia
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm...alright. I'll give it a shot and see what comes up. As always, thanks for the fast help!
reply
    Bookmark Topic Watch Topic
  • New Topic