Hi, I'm working on a project, but I am lost in this class. I'm taking this distant ed Java class, I work 50 hours a week, and I live 2 hours from the school. Needless to say, I can never get in touch with the teacher.
Anyways, I'm trying to grasp this, but I'm having trouble. Here's the scenario:
Here is what I have done:
import java.util.*; public class mixedDrinks { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int choice; do { System.out.println("\n------- Menu----------"); System.out.println("Choose the drink you want to make: "); System.out.println ( "1) Flying Scotsman\n2) Screwdriver\n3) Boilermaker\n0) Quit"); System.out.print ( "Selection: " ); choice = keyboard.nextInt(); switch(choice) { case 1: System.out.println("Flying Scotsman:"); System.out.println ( "* 1 oz Scotch\n* 1 oz Sweet Vermouth\n* 1 dash Bitters\n* 1/4 tsp Simple Syrup\n* Ice" ); System.out.println(); System.out.println("Stir with ice and strain into a glass."); break; case 2: System.out.println ( "Screwdriver:" ); System.out.println("* 1 1/2 oz Vodka\n* 5 oz Orange Juice\n* Ice"); System.out.println(); System.out.println("Pour into a glass half full of ice cubes. Stir well."); break; case 3: System.out.println ( "Boilermaker:" ); System.out.println("* 1 1/2 oz. Blended Whiskey\n* 12 oz. Mug or Pilsner glass of Beer"); System.out.println(); System.out.println("Pour shot of whiskey into shot glass and drop into glass of beer. If preferred, drink whiskey straight and follow with beer chaser."); break; case 0: System.out.println("Bye!"); default: System.err.println ( "I'm sorry, please enter one of the numbers shown above." ); break; } }while (choice != 0); } }Also, how can I make it end by asking the user if they want to quit? . :)
You could
do away with the Do-while and instead use an infinite loop.
while(1)
{
<em> print out menu, get choice</em>
switch(choice)
{
<em> Ask to quit in here, scan input and then break out of switch </em>
}
<em>compare quit options here, then </em><em>either </em><em>break out of infinite loop or the menu will be displayed again</em>
}
About adding up totals, set up some sort of counter variables you can add a price to each time a drink is chosen inside the switch statement, you could add each counter for a full total.