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:

You are planning a party and will be acting as the bartender. You need to write a program to help you mix drinks because, in spite of your excellent bartending skills, you tend to get a little confused as the night gets longer.


Your program needs to display a menu that allows you to select from at least three (3) mixed drinks. Once the drink is selected, the program will display a list of ingredients and amounts and if necessary, brief instructions. Since you need to know how much of your supply is being used, you want to keep a running total of the number of each type drink served as well as a total for overall number of drinks served
.
After displaying the drink instructions, the program should ask the user if it would like to make another drink. The user should have the option to make another drink or quit the program. In either case, the program should display the drink totals mentioned above.

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);
    }
  }

I know this won't ask the user if they want to run it again, or keep a running total of each drink ordered. My question is, how can I make it do that? I don't know how to make it keep a total of every drink made. Then, I need to display that. Also, how can I make it end by asking the user if they want to quit? Any help would be greatly appreciated.

Thanks in advance for any help on this. :)

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)
{
[I]   print out menu, get choice[/I]

switch(choice)
{
[I]  Ask to quit in here, scan input and then break out of switch [/I]
}

[I]compare quit options here, then [/I][I]either [/I][I]break  out of infinite loop or the menu will be displayed again[/I]
}

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.

Sorry while(true) I meant there, not while(1).

Thanks! I got it asking the user if they want to quit, and looping back through it if they don't. Now I gotta figure out how to do a counter.:confused:

eg. If you declare a variable named total and make it = 0.
Each time going through a loop with this line of code;

total = total + price;

the total becomes equal to whatever value total has before going into
to the loop plus the price of drink.

The shortcut operator for the above is
total+=price;

eg. If you declare a variable named total and make it = 0.
Each time going through a loop with this line of code;

total = total + price;

the total becomes equal to whatever value total has before going into
to the loop plus the price of drink.

The shortcut operator for the above is
total+=price;

Awesome! I got it working! I think I'm starting to get the hang of this. It's hard learning a programming language you've never seen before without a teacher to help you.:mrgreen:

Thanks for your help.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.