I have created a switch, and have a variety of subtotals there, (from floats that are in the top of the code)
what I am trying to achieve is this: when a person says selects say flowerChoice and chooses a number 1-7, then choses a colourChoice say 1-6 then chooses sizeChoice say 1-3: I want to add those choices to the println and adds it tot eh amount so that it displays the information on the screen.
I did try adding in the options in like so
("+flowerChoice" +"colourChoice"+ +"sizeChoice"+ Subtotal: £%.2fn", subtotal);
but that did seem to work.. what I am doing wrong here?
I did try adding in the options in like so
("+flowerChoice" +"colourChoice"+ +"sizeChoice"+ Subtotal: £%.2fn", subtotal);
what I was expecting is for it to print the. chosen flower + chosen colour + chosen size then print out the total amount.
but that did seem to work.. what I am doing wrong here?
// Main Menu
System.out.println("Main Menu");
System.out.println("1. Order bouquet and get price.");
System.out.println("2. Display statistics.");
System.out.println("3. Exit the program.");
choice = input.nextLine();
switch (choice) {
case "1":
System.out.println("Choose Flower Types:");
System.out.println("1. Rose ( Cost: £" + rosePrice + " )");
System.out.println("2. Lily ( Cost: £" + lilyPrice + " )");
System.out.println("3. Carnations ( Cost: £" + carnationsPrice + " )");
System.out.println("4. Daffodil ( Cost: £" + daffodilPrice + " )");
System.out.println("5. Gerbera ( Cost: £" + gerberaPrice + " )");
System.out.println("6. Chrysanthemum ( Cost: £" + chrysanthemumPrice + " )");
System.out.println("7. Assorted ( Cost: £" + assortedPrice + " )");
int flowerChoice = input.nextInt();
input.nextLine();
System.out.println("Choose Colour:");
System.out.println("1. White ( Cost: £" + whitePrice + " )");
System.out.println("2. Red ( Cost: £" + redPrice + " )");
System.out.println("3. Pink ( Cost: £" + pinkPrice + " )");
System.out.println("4. Yellow ( Cost: £" + yellowPrice + " )");
System.out.println("5. Blue ( Cost: £" + bluePrice + " )");
System.out.println("6. Mixed ( Cost: £" + mixedPrice + " )");
int colourChoice = input.nextInt();
input.nextLine();
System.out.println("Choose Size:");
System.out.println("1. Small ( Cost: £" + smallPrice + " )");
System.out.println("2. Medium ( Cost: £" + mediumPrice + " )");
System.out.println("3. Large ( Cost: £" + largePrice + " )");
int sizeChoice = input.nextInt();
input.nextLine();
subtotal += flowerChoice == 1 ? rosePrice : // Use ternary operator for flower price
flowerChoice == 2 ? lilyPrice :
flowerChoice == 3 ? carnationsPrice :
flowerChoice == 4 ? daffodilPrice :
flowerChoice == 5 ? gerberaPrice :
flowerChoice == 6 ? chrysanthemumPrice :
assortedPrice;
subtotal += colourChoice == 1 ? whitePrice : // Use ternary operator for color price
colourChoice == 2 ? redPrice :
colourChoice == 3 ? pinkPrice :
colourChoice == 4 ? yellowPrice :
colourChoice == 5 ? bluePrice :
mixedPrice;
subtotal *= sizeChoice == 1 ? smallPrice : // Use ternary operator for size price
sizeChoice == 2 ? mediumPrice : largePrice;
**System.out.printf("Subtotal: £%.2fn", subtotal);**
/*System.out.println("0. Enter 0 to go back to main menu: ");
choice = input.nextLine();*/
break;
case "2":
// Enter information for menu 2
System.out.println("You have chosen option 2 Statstics.");
break;
case "3":
// Exit program
System.out.println("Exiting the program. Goodbye.");
System.exit(0);
default:
System.out.println("Invalid choice. Please enter a valid option.");
}
}
}
Timski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.