Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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!

Welcome to MyCafe --Menu-- 1. Nasi Ayam RM5.00 2.Nasi Lemak RM4.00 3.Nasi Kukus RM5.00 4.Nasi Kandar RM5.00 5.Cancel Enter 1 to Nasi Ayam Enter 2 to Nasi Lemak Enter 3 to Nasi Kukus Enter 4 to Nasi Kandar Enter 5 to Cancel Enter code of the food? :1 You order Nasi Ayam How many Nasi Ayam you want to Buy? :1 You want to buy again? Enter Y for Yes and N for No: Enter 1 to Nasi Ayam Enter 2 to Nasi Lemak Enter 3 to Nasi Kukus Enter 4 to Nasi Kandar Enter 5 to Cancel Enter code of the food? :2 You choose Nasi Lemak How many Nasi Lemak you want to Buy? :1 You want to buy again? Enter Y for Yes and N for No: Enter 1 to Nasi Ayam Enter 2 to Nasi Lemak Enter 3 to Nasi Kukus Enter 4 to Nasi Kandar Enter 5 to Cancel Enter code of the food? :3 You choose Nasi Kukus How many Nasi Kukus you want to Buy? :1 You want to buy again? Enter Y for Yes and N for No: Enter 1 to Nasi Ayam Enter 2 to Nasi Lemak Enter 3 to Nasi Kukus Enter 4 to Nasi Kandar Enter 5 to Cancel Enter code of the food? :4 You choose Nasi Kandar How many Nasi Kandar you want to Buy? :1 You want to buy again? Enter Y for Yes and N for No: n Total price is : RM19.0 Enter a payment : RM20.0 an maris The change is : RM1.0 This is your receipt Total price : RM19.0 Paid : RM20.0 Your changed : RM1.0 This is your receipt Total price : RM19.0 Paid : RM20.0 Your changed : RM1.0 This is your receipt Total price : RM19.0 Paid : RM20.0 Your changed : RM1.0 This is your receipt Total price : RM19.0 Paid : RM20.0 Your changed : RM1.0 BUILD SUCCESSFUL (total time: 36 seconds)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL 10 High Performance Expert Techniques For Query Optimization High Availability And Efficient Database Maintenance

Authors: Ibrar Ahmed ,Gregory Smith ,Enrico Pirozzi

3rd Edition

1788474481, 978-1788474481

More Books

Students also viewed these Databases questions

Question

I am paid fairly for the work I do.

Answered: 1 week ago

Question

I receive the training I need to do my job well.

Answered: 1 week ago