the problem that I am having is that, I have created a series of Strings with arrays with the names of the items and a doubles arrays for the prices. for three sets of conditions flowers, colours, size. I have also created a switch method for the menu now this is where I am stuck. when I call to the scanner to get the information on the flowers, colours and sizes, it won’t work. the menu shows up but if I go to place an order for the listed flowers they are not showing up. I have been advised not to use the scanner is there another way to do this if so how?
your text
import java.util.Scanner;
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) {
try (Scanner scanner = new Scanner(System.in)) {
int Choice;
do
{
displayMenu();
Choice = getUserChoice(scanner);
switch (Choice) {
case 1:
// use scanner to display menu options for flowers col ours and size
orderDetailsAndPriceCalculation(scanner);
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(Scanner scanner) {
int choice = -1;
try {
choice = Integer.parseInt(scanner.nextLine());
} catch (NumberFormatException e) {
// Invalid input, choice will remain -1
}
return choice;
}
public static void orderDetailsAndPriceCalculation(Scanner scanner) {
int i;
// adds values for chosen ammounts for orders and puts them into the scanner
int flowerChoice = getFlowerChoice(scanner);
if (flowerChoice == -1) return;
int colourChoice = getColourChoice(scanner);
if (colourChoice == -1) return;
int sizeChoice = getSizeChoice(scanner);
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");
}
}''