This article shares the specific code of Java implementing a simple meal ordering system for your reference. The specific content is as follows
import ; import .*; public class OrderingMsg { public static void main(String[] args) { // Data subject: a set of order informationString[] names = new String[4]; // Name of the ordererString[] dishMegs = new String[4]; // Selected dishesint[] times = new int[4]; // Meal delivery timeString[] addresses = new String[4]; // Delivery addressint[] states = new int[4]; // Order status: 0: Reservation 1: Completeddouble[] sumPrices = new double[4]; // lump sum //Initialize 2 order informationnames[0] = "Zhang Qing"; dishMegs[0] = "Braised Hairfish 2 servings"; times[0] = 12; addresses[0] = "No. 207 Tiancheng Road"; sumPrices[0] = 76.0; states[0] = 1; names[1] = "Zhang Qing"; dishMegs[1] = "2 servings of fish-flavored shredded pork"; times[1] = 18; addresses[1] = "No. 207 Tiancheng Road"; sumPrices[1] = 20.0; // Dishes to choose fromString[] dishNames = { "Braised Hairfish", "Fish-flavored shredded pork", "Seasonal Fresh Vegetables" }; // Name of the dishdouble[] prices = new double[] { 38.0, 20.0, 10.0 }; // Single price of the menuint[] praiseNums = new int[3]; Scanner input = new Scanner(); int num = -1; // The user enters 0 and returns to the main menu, otherwise exit the systemboolean isExit = false; // Sign whether the user exits the system: true: exits the system ("\nWelcome to use the "Foodie Alliance Food Ordering System""); // Loop: Display the menu and perform corresponding functions according to the number selected by the userdo { // Show menu("****************************"); ("1. I want to order a meal"); ("2. Check the meal bag"); ("3. Sign for orders"); ("4. Delete the order"); ("5. I want to like it"); ("6. Exit the system"); ("****************************"); ("Please select:"); int choose = (); // Record the function number selected by the userboolean isAdd = false; //Record whether you can order a mealboolean isSignFind = false; //Find the order to be signedboolean isDelFind = false; //Find the order to be deleted// Perform the corresponding function according to the function number selected by the userswitch (choose) { case 1: // I want to order a meal("***I want to order food***"); ("Please enter the name of the orderer:"); String name=(); isAdd=true; int j = 0; for (; j < ; j++) { //todo if(names[j]==null){ names[j]=name; break; } else { isAdd=true; } } if(!isAdd){ ("Sorry, your meal bag is full!"); } else { ("Serial Number"+"\t"+"Dish Name"+"\t"+"price"); for(int i=0;i<;i++){ (i+1+"\t"+dishNames[i]+"\t"+prices[i]+"\n"); } ("Please enter the dish number:"); int dishNum=(); ("Please enter the quantity of dishes:"); int dishCnt=(); String dishMeg=dishNames[dishNum-1]+dishCnt+"share"; dishMegs[j]=dishMeg; ("Please enter the delivery address:"); String Addr=(); addresses[j]=Addr; ("Please enter the delivery time:"); int time=(); times[j]=time; double sumPrice=prices[dishNum-1]*dishCnt; double deliCharge=(sumPrice>50)?0:5; ("Meal Fee:"+sumPrice+"Yuan, meal delivery fee:"+deliCharge+"Yuan, total:"+(sumPrice+deliCharge)+"Yuan."); sumPrices[j]=sumPrice+deliCharge; } break; case 2: // Check out the dining bag("***View Dining Bags***"); ("Serial number\tSubscriber\tMeal information\tDate delivery date\tDelivery address\tTotal amount\tOrder status"); //todo for(int i=0;names[i]!=null;i++) { String sta=(states[i]==1)?"Completed":"Reserved"; ((i+1)+"\t"+names[i]+"\t"+dishMegs[i]+"\t"+times[i]+"\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+sta+"\n"); } break; case 3: // Sign for orders("***Sign orders******"); //todo ("Serial number\tSubscriber\tMeal information\tDate delivery date\tDelivery address\tTotal amount\tOrder status"); for(int i=0;names[i]!=null;i++) { String sta=(states[i]==1)?"Completed":"Reserved"; ((i+1)+"\t"+names[i]+"\t"+dishMegs[i]+"\t"+times[i]+"\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+sta+"\n"); } ("Please select the order number to sign for:"); int n=(); states[n-1]=1; ("Serial number\tSubscriber\tMeal information\tDate delivery date\tDelivery address\tTotal amount\tOrder status"); for(int i=0;names[i]!=null;i++) { String sta=(states[i]==1)?"Completed":"Reserved"; ((i+1)+"\t"+names[i]+"\t"+dishMegs[i]+"\t"+times[i]+"\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+sta+"\n"); } break; case 4: // Delete the order("***Delete Order***"); ("Serial number\tSubscriber\tMeal information\tDate delivery date\tDelivery address\tTotal amount\tOrder status"); for(int i=0;i<4;i++) { String sta=(states[i]==1)?"Completed":"Reserved"; ((i+1)+"\t"+names[i]+"\t"+dishMegs[i]+"\t"+times[i]+"\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+sta+"\n"); } ("Please enter the order number to be deleted:"); //todo int m=(); for(int k=m; k<4;k++) { names[k-1]=names[k]; dishMegs[k-1]=dishMegs[k]; times[k-1]=times[k]; addresses[k-1]=addresses[k]; sumPrices[k-1]=sumPrices[k]; states[k-1]=states[k]; } ("Serial number\tSubscriber\tMeal information\tDate delivery date\tDelivery address\tTotal amount\tOrder status"); for(int i=0;i<4;i++) { String sta=(states[i]==1)?"Completed":"Reserved"; ((i+1)+"\t"+names[i]+"\t"+dishMegs[i]+"\t"+times[i]+"\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+sta+"\n"); } break; case 5: // I want to like("***I want to like******"); // Show dish information("Serial Number" + "\t" + "Dish Name"+"\t"+"unit price"); for(int i=0;i<;i++){ (i+1+"\t"+dishNames[i]+"\t"+prices[i]+"\t"+praiseNums[i]+"praise"+"\n"); } //todo ("Please enter the like number:"); int number=(); praiseNums[number-1]=praiseNums[number-1]+1; ("Serial Number" + "\t" + "Dish Name"+"\t"+"unit price"); for(int i=0;i<;i++){ (i+1+"\t"+dishNames[i]+"\t"+prices[i]+"\t"+praiseNums[i]+"praise"+"\n"); } break; case 6: // Exit the systemisExit = true; break; default: //Exit the systemisExit = true; break; } if (!isExit) { ("Input 0 returns:"); num = (); } else { break; } } while (num == 0); ("Thank you for using it, welcome next time!"); } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.