• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

need help with my switch statement

 
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
Posts: 12751
51
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: 64707
226
  • 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.
 
Marshal
Posts: 6859
470
Mac OS X VI Editor BSD Linux
  • 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
Marshal
Posts: 6859
470
Mac OS X VI Editor BSD Linux
  • 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: 64707
226
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!