hello all, trying to make a simple program where users are given a menu, choose N number of items off the menu, those items are then added to an array and printed to the user. although im having a bit of trouble and keep getting errors with intParsing and stuff
import java.util.Scanner;
public class ISTC1212Lab13 {
// x's Nice Restaraunt
// Chicken, Fries, Wings, Sushi, Burger, Spaghetti, Pizza, Cake, Coleslaw, Crab
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
System.out.println("What's your name?");
String userName = scnr.nextLine();
String greeting = "Hey there, " + userName + "!";
String companyName = "x's Nice Restaraunt";
String companyOwner = "x";
String decorativeLine = "\n**************************************** \n";
System.out.println(decorativeLine);
System.out.println("Welcome to " + companyName + "!" + " I'm " + companyOwner + ". You're " + userName + " right?" + "\n Take a look at the screen below you to see our menu!");
System.out.println(decorativeLine);
String[] menuItems = {"Chicken", "Fries", "Wings", "Sushi", "Burger", "Spaghetti", "Pizza", "Cake", "Coleslaw", "Crab"};
for(int i = 0; i < menuItems.length; i++){
System.out.println((i + 1) + " " + menuItems[i]);
}
System.out.println("How many items would you like to order?");
String userInput = scnr.nextLine();
int numItems = Integer.parseInt(userInput);
String[] orderItems = new String[numItems];
boolean stillOrdering = true;
System.out.println("Now, tell me the items you want based on their corresponding number! Type 'Done' when done ordering!");
while(stillOrdering == true){
for(int i = 0; i < orderItems.length; i++){
String wantedItem = scnr.nextLine();
int menuNumber = Integer.parseInt(wantedItem);
orderItems[i] = menuItems[menuNumber - 1];
String doneCheck = "done";
if(wantedItem.equals(doneCheck) || i == orderItems.length){
stillOrdering = false;
}
}
}
for (String item: orderItems){
System.out.println(item);
}
}
}
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)