what I am trying to accomplish is a simple menu that gets flowers + prices colours + prices and size + prices then add it together to give you a subtotal. but in my IDE all of the inputs are showing as red saying that input can not be resolved.
here is the code that I have done so far:
public class MenuTest2B {
// create flowers + price arrays
public static final String[] FLOWERS = {"Roses", "Lilys", "Carnations", "Daffodils", "Gerberas", "Chrysanthemums", "Assorted"};
public static final double[] FLOWER_PRICES = {1.2, 1.3, 1.0, 1.0, 1.1, 1.1, 0.8};
// create colours + price arrays
public static final String[] COLOURS = {"White", "Red", "Pink", "Yellow", "Blue", "Mixed"};
public static final double[] COLOUR_PRICES = {1.3, 1.2, 1.1, 1.1, 1.2, 1.0};
// create size + price arrays
public static final String[] SIZES = {"Small", "Medium", "Large"};
public static final double[] SIZE_PRICES = {5.5, 7.5, 9.5};
public static void main(String[] args) {
int choice;
do
{
displayMenu();
choice = getUserChoice();
switch (choice) {
case 1:
// use scanner to display menu options for flowers col ours and size
orderDetailsAndPriceCalculation();
break;
case 2:
summaryStatistics();
break;
case 3:
System.out.println("You are exiting the program... Goodbye");
break;
default:
System.out.println("Invalid input. Please select a valid option.");
}
} while (choice != 3);
}
}
private static void displayMenu() {
System.out.println("Main Menu");
System.out.println("1. Order a bouquet and get the price.");
System.out.println("2. Display statistics");
System.out.println("3. Exit");
}
public static int getUserChoice() {
int choice = -1;
try {
choice = Integer.parseInt(input.nextLine());
} catch (NumberFormatException e) {
// Invalid input, choice will remain -1
}
return choice;
}
public static void orderDetailsAndPriceCalculation() {
// adds values for chosen ammounts for orders and puts them into the scanner
int flowerChoice = getUserChoice();
int flowerchoice = input.nextInt(); input.nextLine();
if (flowerChoice == -1) return;
int colourChoice = getUserChoice();
int colourchoice = input.nextInt(); input.nextLine();
if (colourChoice == -1) return;
int sizeChoice = getUserChoice();
int sizechoice = input.nextInt(); input.nextLine();
if (sizeChoice == -1) return;
// calculates the input order details (Flower+Colour)*Size
double totalPrice = (FLOWER_PRICES[flowerChoice] + COLOUR_PRICES[colourChoice]) * SIZE_PRICES[sizeChoice];
// PRINT TOTAL AMOUNT
// AND DETAILS OF BOUQUET
System.out.println("Bouquet: " + SIZES[sizeChoice] + " " + COLOURS[colourChoice] + " " + FLOWERS[flowerChoice] + ".");
System.out.println("Bouquet Price: £" + totalPrice);
}
public static void summaryStatistics() {
System.out.println("Summary statistics provided");
}