• Post Reply Bookmark Topic Watch Topic
  • New Topic

need help with my switch statement  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm really new to java and having trouble working out what should be inside my switch statement for each case as the user selects a ticket they then need to be prompted to input a quantity then once done to go to the main menu with the subtotal until they exit completely.

 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest you're doing it wrong. You shouldn't write a switch statement and then try to figure out what goes inside it...you should figure out what your program needs to do, and then decide if a switch statement is the way to do it.

One of the hardest things to learn when you are new is that programming is probably 90% thinking, and 10% typing.

but having said that...you state:
"for each case...they then need to be prompted to input a quantity"
That implies to me there should be a method, something like "getQuantity" that prompts, gets an input, validates it as a valid quantity, and then returns an int.  Then you'd call is as needed.  But if you are going to call it for every possible case, maybe it shouldn't be in your switch block at all...
 
Marshal
Posts: 56605
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I can see all sorts of other problems, causing your methods to become too long. You aren't creating a Ticket class, which would have options (or subtypes) for a single ride or multiple rides. Otherwise what will happen is that you will have multiple switches each with another lot of keyboard input, and  lots of code repetition.
Why are you using option panes for keyboard input? That is very old‑fashioned style.
 
Sheriff
Posts: 4932
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a programmer, either starter or experienced you are responsible for writing well formatted and well indented code. It is unacceptable to do otherwise.
 
Liutauras Vilda
Sheriff
Posts: 4932
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch

This is how Campbell increases his post count, so I copied him.
 
Campbell Ritchie
Marshal
Posts: 56605
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, Campbell increases his post count by saying, “That's a pleasure,” or, “You're welcome,” at the end of every thread.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!