How do I record every user Input and then display all of it in the scream. In my code i ask the user
for a series of food item, then i ask for the toppings. I need to display every input of food and toppings the
user enters. The output must look like this
Here is your order <name>
Appetizer: [ Wings, Blue cheese, Ranch ]
Main Course: [ Hamburger: mushrooms , Advocado ]
Dessert: [ Pie: Powder Sugar, Scoop of IceCream ]
This is my code:
import java.util.Scanner;
class Main {
static void display(String menu[]) {
for (int i = 0; i<menu.length; i++) {
System.out.println(i + " - " + menu[i]);
}
System.out.print("Enter the number for your selection: ");
}
public static void main(String[] args) {
int selection = 0;
int Appetizerselection = 0;
int MainCourseSelection = 0;
int DessertSelection = 0;
int AppetizerToppingsSelection = 0;
int MainCourseToppingsSelection = 0;
int DessertSelectionToppings = 0;
int i = 0;
String list = "";
String MainMenu[] = {"Nothing", "Appetizer", "Main Course",
"Dessert"};
String Appetizer[] = {"Nothing", "Wings", "Salad", "Fries"};
String AppetizerToppings[] = {"Nothing", "Blue Cheese", "Ranch",
"Cheese"};
String MainCourse[] = {"Nothing", "Steak", "Hamburger",
"Pasta"};
String MainCourseToppings[] = {"Nothing", "Mushrooms", "Advocado",
"Black Olives"};
String Dessert[] = {"Nothing", "Chocolate Cake", "Pie",
"Cookies"};
String DessertToppings[] = {"Nothing", "Powder Sugar", "Scoope of
IceCream", "Condense Milk"};
Scanner scan = new Scanner(System.in);
System.out.println("Welcome to the food festival");
while(true){
System.out.println("Would you like to place an order");
String input = scan.nextLine();
if (input.equalsIgnoreCase("Yes")) {
System.out.println("What is your name for the order?");
String name = scan.nextLine();
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Main
Menu@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
do {
System.out.println("Select from menu, " + name);
display(MainMenu);
selection = scan.nextInt();
if (selection > 0 && selection<MainMenu.length)
{
System.out.println("Current String: " + selection);
}
////////////////////////////////////////////////Appetizer
Menu//////////////////////////////////////////////////////////////////////
if (selection == 1) {
System.out.println("Appetizer Menu:");
do {
display(Appetizer);
Appetizerselection = scan.nextInt();
if (selection > 0 && selection<Appetizer.length)
{
Appetizer[selection];
}
if (Appetizerselection > 0) {
System.out.println("Topping Menu:");
do {
display(AppetizerToppings);
AppetizerToppingsSelection = scan.nextInt();
if (AppetizerToppingsSelection > 0)
System.out.println("Current String: " +
AppetizerToppings[AppetizerToppingsSelection]);
} while (AppetizerToppingsSelection != 0);
}
} while (Appetizerselection != 0);
}
//*************************************************** Main Course
Menu*************************************************************
if (selection == 2) {
System.out.println("Main Course Menu:");
do {
display(MainCourse);
MainCourseSelection = scan.nextInt();
if (selection > 0 && selection<MainCourse.length)
{
System.out.println("Current String: " +
MainCourse[selection]);
}
if (MainCourseSelection > 0) {
System.out.println("Topping Menu:");
do {
display(MainCourseToppings);
MainCourseToppingsSelection = scan.nextInt();
if (MainCourseToppingsSelection > 0) System.out.println("Current
String: " + MainCourseToppings[MainCourseToppingsSelection]);
} while (MainCourseToppingsSelection != 0);
}
} while (MainCourseSelection != 0);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++Dessert
Menu++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if (selection == 3) {
System.out.println("Dessert Menu");
do {
display(Dessert);
DessertSelection = scan.nextInt();
if (selection > 0 && selection<Dessert.length)
{
System.out.println("Current String: " + Dessert[selection]);
}
if (DessertSelection > 0) {
System.out.println("Topping Menu");
do {
display(DessertToppings);
DessertSelectionToppings = scan.nextInt();
if (DessertSelectionToppings > 0) System.out.println("Current
String: " + MainCourseToppings[MainCourseToppingsSelection]);
} while (DessertSelectionToppings != 0);
}
} while (DessertSelection != 0);
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
} while (selection != 0);
System.out.println( Appetizer[selection] );
System.out.println("Thank you for ordering come again");
break;
}
else if (input.equalsIgnoreCase("no")) {
System.out.println("Thank you for stopping by, maybe next time
you'll sample our menu");
break;
}
}
}
}
hello student, you are most welcome here.
I am just giving you the most suitable and relatable answer please
go through it and see how can we record any data at runtime using
generic. I did not go or changes in your code because your idea is
different and it very long code. But I have to give you here an
idea for your problem.
For the record your data as like in your program you should use
ArrayList in java because in your code you are proceeding at run
time, therefore, the idea behind that to record all user activity
used ArrayList.
Now let's see how ArrayList works and how to use it. I can not
implement or change all of your code because i don't know why
exactly you wrote your line and what is the reason behind it. I
damm sure I must give you an idea which will guide you to get your
whole working code.
if you like my work then please give me a thumb up. happy
coding.
in your code there can maximum optimized suitable and easy way to solve this question. if you have any quarry then please ask in comment.
I am just gonna write a small program that will record all input(history) and display it.
here is some student they will enter their name and grade and we will record it and display it.
package arrayList;
import java.util.Scanner;
import java.util.ArrayList;
public class Student
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
ArrayList<String> sName = new ArrayList<String>(); //
just initializede an array list to record student name.
boolean test=true;
while (test)
{
System.out.println(" Enter Name");
sc.nextLine(); // it is for enter button for some JDK if you jdk is working correctly then disable it.
String s = sc.nextLine();
if(s.equals("N"))
{
break;
}
else
{
sName.add(s);
}
ArrayList<Double> grde = new ArrayList<Double>(); //
just initializede an array list to record grade.
System.out.println("Enter grade");
// I am just taken dummy fore record in your problem you can make
boundation to selected item length.
for (int j = 0; j < 4; j++)
{
Double g = sc.nextDouble();
grde.add(g);
}
// now let print all recorded your data.
System.out.println(sName);
System.out.println(" ");
System.out.print(grde);
}
}
}
How do I record every user Input and then display all of it in the scream....
Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...
Help check why the exception exist do some change but be sure to use the printwriter and scanner and make the code more readability Input.txt format like this: Joe sam, thd, 9, 4, 20 import java.io.File; import java.io.PrintWriter; import java.io.IOException; import java.io.FileNotFoundException; import java.io.FileWriter; import java.util.Scanner; public class Main1 { private static final Scanner scan = new Scanner(System.in); private static String[] player = new String[622]; private static String DATA = " "; private static int COUNTS = 0; public static...
How do I modify this to let the user input the size of the matrix? The lowest size is 4 and the largest size is 16. import java.util.*; public class Test1 { public static void main(String[] args) { int[][] matrix = new int[4][4]; // create 4 by 4 matrix (need user input???) // generate 1's and 0's for each each rows and columns // and track largest row index with the most ones int largestRI...
Debug and fix the Java console application that uses 2 dimensional arrays but the application does not compile nor execute. Student enters only integers to select courses for registration from a menu. No data type validation of the user menu selection is checked or required. The program terminates only when the student closes it. No registration of other courses not displayed by the program . No registration more than once for the same course. No registration for more than 9...
(How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...
kindly Explain, briefly IN PLAIN ENGLISH, how this exercise was completed and the algorithm you used /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ // package u10a1_ooconsoleregisterforcourse; import java.util.Scanner; /** * * @author omora */ public class U10A1_OOConsoleRegisterForCourse { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO...
This is the code we have to edit, i know how to do everything
except finding if the x and y are in the space, please explain to
me when you do the code. We are using addshape() api and more.
public class Skeleton { public static void main(String[] args) { //================================ //== Setting up game window ====== SpaceGame myGame; //declaring the object form the class Scanner scan = new Scanner(System.in); System.out.println("What is the window name? "); //window title text...
C Program: How do I display if the input is invalid for input not in the range from (1-10); #include <stdio.h> int main(){ int number,i; // prompt user to enter number of lines to print Bad Dog printf("Enter a number of lines to print Bad Dog:"); scanf("%d",&number); for(i=0;i<number;i++){ goto nonono; nonono: printf("Bad Dog\n"); } return 0; }// end main
1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Deposit Cash. B. Withdraw Cash X. Exit Enter your Selection: 3. Prompt for the value menuChoice. 4. If menuChoice is "A", display "Do Deposit" and redisplay the menu. If menuChoice is "B", display "Do withdrawal" and redisplay the menu. If...
Sample Execution – Level 3
Welcome to your Menu Creation system.
How many items would you like to have on your menu? 2
Create your menu!
Enter item #1: Coffee
Enter the number of toppings: 2
Enter topping #1: Whipped Cream
Enter topping #2: Cinnamon
Enter item #2: Tea
Enter the number of toppings: 2
Enter topping #1: Milk
Enter topping #2: Sugar
May I take your order?
This is the menu:
Coffee
Tea
Pop
How many items would you...