Create a menu array of strings to store menu items Create an array of doubles to
ID: 3859457 • Letter: C
Question
Create a menu array of strings to store menu items Create an array of doubles to store the menu item prices Modify your menu.txt so that each menu item has two associated lines. The first contains the name of the item (read by getline). The next contains the price. Use file input to store in the appropriate place in your double array. You will also need to use the ignore function with file input to skip the return character after your double. You must use at least one range-based for loop in your program. You may use it to initialize, assign values to, or print from one or more of your arrays. You must modify one or more of your functions to accept an array as an argument/parameter. Your entrée/menu item prices must be read from the menu item price array. Modify your bill calculation for loop to print out the menu for each iteration and have the user choose an entrée. Based on the option selected, add the appropriate price (remember that indices are off by one!). No prices should be read from the keyboard.
Explanation / Answer
import java.util.Scanner;
public class Studentarray {
public static void main(String[] args) {
int choice = 0;
int[] stringArray = {};
do{
String[] stringarray = new String[20];
System.out.println("----------------Studentarray---------------");
System.out.println();
System.out.println("1. Add Students");
System.out.println("2. Delete Students");
System.out.println("3. Search for student");
System.out.println("4. Print all Students");
System.out.println("5. exit");
Scanner scanchoice = new Scanner(System.in);
choice = scanchoice.nextInt();
if (choice ==1){
Scanner scannames = new Scanner(System.in);
System.out.println("Please enter the student names into the array");
int i = 0;
for(i = 0; i<stringarray.length; i++){
String temp =scannames.nextLine();
stringarray[i]=temp.toLowerCase();
if(i==(stringarray.length-1)){
System.out.println("successfully filled up array fully");
System.out.println();
}
}
}
if(choice==2){
}
if(choice==3){
for(int p = 0; p<stringarray.length; p++){
System.out.println(stringarray[p]);
}
int x=0;
Scanner scannames1 = new Scanner(System.in);
System.out.println("Enter name of student you want to search for: ");
System.out.println();
String search=scannames1.nextLine();
String searchName=search.toLowerCase();
for(int p=0;p<20;p++){
if(searchName.equals(stringarray[p])){
x=1;
}
else{
x=0;
}
}
if(x==1){
System.out.println("We have a match in our database for "+ searchName);
}
else if (x==0){
System.out.println("No match for "+ searchName);
}
}
if (choice ==4){
System.out.println("List of names:");
for(int p = 0; p<stringarray.length; p++){
System.out.println(stringarray[p]);
}
}
}while(choice!=5);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.