Write a program that when run, produces a menu showing beer brands and their prices and then prompts the user enter his/her choice (1,2,3 or 4). The user is then asked how many bottles he/she wants. He is then given the total cost (depending on the cost of the beer chosen) as the output. See sample dialog below. If he/she enters an invalid choice e.g. 8, he/she should get an error message.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("1. Kingfisher - 3.28$");
System.out.println("2. Heineken - 2.12$");
System.out.println("3. Carlsberg - 4.30$");
System.out.println("4. Corona - 1.57$");
System.out.println();
System.out.println("Choose the bear: Type number:");
int choice = Integer.parseInt(scanner.nextLine());
double pricePerBottle = 0.0;
switch (choice){
case 1: pricePerBottle = 3.28;
break;
case 2: pricePerBottle = 2.12;
break;
case 3: pricePerBottle = 4.30;
break;
case 4: pricePerBottle = 1.57;
break;
default:
System.out.println("Wrong input. Type number 1 - 4");
}
if (pricePerBottle != 0.0) {
System.out.println("Input number of bottles:");
int amount = Integer.parseInt(scanner.nextLine());
System.out.println("The total cost is " + amount * pricePerBottle);
}
Comments
Leave a comment