Question
Please help me create a search method so that the user can search food that they have added/order, and a delete method so users can
Please help me create a search method so that the user can search food that they have added/order, and a delete method so users can delete food that they have added/order in case they have changed their mind and do not want it anymore. Moreover, I want the user to have an option to search or delete after they input the letter N for not continue buying. Please refer to the SAMPLE OUTPUT.
This is my code in Java:
import java.util.Scanner;
public class Project {
public static void main(String[] args) {
int i = 0;
int code;
String[] food;//declare
food=new String[4];
food[0]="Nasi Ayam";
food[1]="Nasi Lemak";
food[2]="Nasi Kukus";
food[3]="Nasi Kandar";
double[] price = new double [4];
price [0] = 5.00;
price [1] = 4.00;
price [2] = 5.00;
price [3] = 5.00;
menu(food);
order(price);
}
public static Scanner input = new Scanner(System.in);
public static String repeat;
public static int choose,quantity=1;
public static double total=0,pay;
public static double change=0;
public static void menu(String[] food){//choose your menu
System.out.println(" Welcome to MyCafe ");
System.out.println(" ----------------Menu----------------");
System.out.println(" 1."+food[0]+ " RM5.00");
System.out.println(" 2."+food[1]+ " RM4.00");
System.out.println(" 3."+food[2]+ " RM5.00");
System.out.println(" 4."+food[3]+ " RM5.00");
System.out.println(" 5.Cancel");
}
public static void order(double[] price){
System.out.println(" Enter 1 to Nasi Ayam Enter 2 to Nasi Lemak Enter 3 to Nasi
Kukus Enter 4 to Nasi Kandar Enter 5 to Cancel");
System.out.print("Enter code of the food? :");
choose = input.nextInt();//enter food code based on menu
//conditions
if(choose==1){
System.out.println("You order Nasi Ayam");
System.out.print("How many Nasi Ayam you want to Buy? :");
quantity =input.nextInt();//quantity that you want
total = total +(quantity*price[0]);//calculate the total of food
System.out.println("You want to buy again? ");
System.out.println("Enter Y for Yes and N for No : ");
repeat = input.next();//repeat other menu
if(repeat.equalsIgnoreCase("Y")){
order(price);
}else{
System.out.println("Total price is : RM" + total);
System.out.print("Enter a payment : RM");
pay = input.nextDouble();//enter your payment
if(pay System.out.println("Not enough payment"); }else{ change = pay-total;//money change System.out.println("The change is : RM" + change); } } }else if(choose==2){ System.out.println("You choose Nasi Lemak"); System.out.print("How many Nasi Lemak you want to Buy? :"); quantity =input.nextInt(); total = total +(quantity*price[1]); System.out.println("You want to buy again? "); System.out.println("Enter Y for Yes and N for No : "); repeat = input.next(); if(repeat.equalsIgnoreCase("Y")){ order(price); }else{ System.out.println("Total price is : RM" + total); System.out.print("Enter a payment : RM"); pay = input.nextDouble(); if(pay System.out.println("Not enough payment"); }else{ change = pay-total; System.out.println("The change is : RM" + change); } } }else if(choose==3){ System.out.println("You choose Nasi Kukus"); System.out.print("How many Nasi Kukus you want to Buy? :"); quantity =input.nextInt(); total = total +(quantity*price[2]); System.out.println("You want to buy again? "); System.out.println("Enter Y for Yes and N for No : "); repeat = input.next(); if(repeat.equalsIgnoreCase("Y")){ order(price); }else{ System.out.println("Total price is : RM" + total); System.out.print("Enter a payment : RM"); pay = input.nextDouble(); if(pay System.out.println("Not enough payment"); }else{ change = pay-total; System.out.println("The change is : RM" + change); } } }else if(choose==4){ System.out.println("You choose Nasi Kandar"); System.out.print("How many Nasi Kandar you want to Buy? :"); quantity =input.nextInt(); total = total +(quantity*price[3]); System.out.println("You want to buy again? "); System.out.println("Enter Y for Yes and N for No : "); repeat = input.next(); if(repeat.equalsIgnoreCase("Y")){ order(price); }else{ System.out.println("Total price is : RM" + total); System.out.print("Enter a payment : RM"); pay = input.nextDouble(); if(pay System.out.println("Not enough payment"); }else{ change = pay-total; System.out.println("The change is : RM" + change); } } } else if(choose==5){ System.out.print(Invalid ); System.exit(0);//exit program } //your receipt { System.out.println("-----------------------------------------------"); System.out.println("This is your receipt"); System.out.println("Total price : RM"+total); System.out.println("Paid : RM"+pay); System.out.println("Your changed : RM"+change); System.out.println("-----------------------------------------------"); } } }//end of program Sample Output: Please help me create a search method so that the user can search food that they have added/order, and a delete method so users can delete food that they have added/order in case they have changed their mind and do not want it anymore. Moreover, I want the user to have an option to search or delete after they input the letter N for not continue buying. Please refer to the SAMPLE OUTPUT. Thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started