Project case — Foodie Alliance
I. Project Preparation:
1. Development Environment:
- JDK1.8
- IntelliJ IDEA
2. Technical Analysis:
- Can understand the basic concept of program – program
- Use variables, data types
- Can write programs using sequential, select, loop, jump statements
- You can use arrays
3. Task Description:
As long as you move your finger, you can deliver food “, online ordering by modern people, is the development of an online ordering system, the functions are as follows:
- I want to order a meal
- View the meal bags
- To sign for the order
- Delete the order
- I’d like praise
- Log out
Ii. Requirements:
1. Demand analysis:
Buyer:
Buyer order basic information – username, time, address, quantity, etc
The seller:
Dish information – unit price, variety, number of likes
Module division:
Order — add –insert -c (create) View bag — query –read -r Sign order — modify –update -u delete order –delete –delete -d I like — Accessibility exit system — flow control
2. Writing Requirements:
Project name –Foods package name — CN.xx. controll class name –OrderingMsg Project preparation needs to be made into running JAR and BAT files
3. Compilation steps:
Define variables — test data — build frames: do… While nested switch, will jump to switch with a number to replace View order View before — Loop Before check is empty Add order Job: Complete whether to continue function add Note Separate operation of Printing receipts and array add data Sign order: Judge sign case: Delete the order: move all the data after the data to be deleted forward, and then empty the last waste data. I click “Like” : display the menu, and then add 1 to the designated “like” dishes
Iii. Code Analysis:
1. Define variables:
// Define the buyer variable -- array
String[] names=new String[4]; // The name of the person who ordered the meal
int[] times=new int[4]; // Reservation time - on the hour
String[] addresses=new String[4]; // Reservation address
String[] dishMegs=new String[4]; // Information about selected dishes
double[] sumPrices=new double[4]; / / total amount
int[] states=new int[4]; // Order status information
// Define the seller's menu variable -- array
String[] dishNames={"Big elbows"."Meat in pot"."Spicy duck head"."Spicy shrimp"}; // Menu information
double[] prices={59.58.48.69}; // Menu price
int[] praiseNums={4.5}; // The number of likes
Copy the code
2. Framework module:
do{
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println(1. I'd like to order a table.);
System.out.println("Step 2 Check your lunch bag");
System.out.println("3. Sign for the order");
System.out.println("4. Delete order");
System.out.println("5. I like it");
System.out.println("6. Log out");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println("Please select");
num=input.nextInt();
switch (num) {
case 1:
System.out.println("I'd like to order a meal.");
break;
case 2:
System.out.println("Check your lunch bag.");
break;
case 3:
System.out.println("Sign for order");
break;
case 4:
System.out.println("Delete order");
break;
case 5:
System.out.println("I give it a thumbs up.");
break;
case 6:
System.out.println(Log out of the system);
isExit=true;
break;
default:
isExit=true;
break;
}
// Determine whether to go back to the level 1 menu
if(! isExit){ System.out.println("Enter 0 and return");
num=input.nextInt();
}else{
break; }}while(num==0);
System.out.println("Welcome next time!");
Copy the code
Step 3 Check your bag:
for (int i = 0; i <names.length; i++) {
// Check -- If the user information is empty, the order will not be printed
if(names[i]! =null){
String state=(states[i]==0)?"Booked":"Done";
String sumPrice=sumPrices[i]+"Yuan";
String time=times[i]+"When";
System.out.println((i+1) +" \t\t"+names[i]+" \t\t"
+dishMegs[i]+" \t\t"+time
+" \t\t"+addresses[i]+" \t\t"+sumPrice+" \t\t"+state); }}Copy the code
4. I’d like to make a reservation.
for (int i = 0; i < names.length; i++) {
// Add content to array - need to get array empty position - first position - loop end
if(names[i]==null) {// The entry decision marks a space where data can be added -- to modify the mark
isAdd=true;
// Add order
System.out.println("Please enter user name"); // Simulate login
String name=input.next();
// Print menu information
System.out.println("No. \t Dish name \t unit price \t Number of likes");
for (int j = 0; j < dishNames.length; j++) {
String price=prices[j]+"Yuan";
String praise=(praiseNums[j]>0)? praiseNums[j]+"Praise":"";
System.out.println((j+1) +" \t"+dishNames[j]+" \t"+price+" \t"+praise);
}
System.out.println("Please enter the serial number of your choice.");
int chooseDish=input.nextInt();
System.out.println("Please enter the number of shares purchased.");
int number=input.nextInt();
// Process order information and order totals
String dishMeg=dishNames[chooseDish-1] +""+number+"份";
double sumPrice=prices[chooseDish-1]*number;
// Determine whether delivery is required: over 50 free delivery
double deliCharge=(sumPrice>=50)?0:5; / / shipping fee
// Delivery time - If the time input is incorrect, repeat the input until the input is correct 10-20
System.out.println("Please enter the delivery time (on the hour of 10-20)");
int time=input.nextInt();
/*while(! (time>=10&&time<=20)){system.out.println (" you entered an incorrect time, please re-enter "); time=input.nextInt(); } * /
while(time<10 ||time>20){
System.out.println("The time you entered is incorrect. Please re-enter it.");
time=input.nextInt();
}
System.out.println("Please enter delivery address");
String address=input.next();
// Print the receipt
System.out.println("Reservation successful!");
System.out.println("What's your order?"+dishMeg);
System.out.println("The cost of the meal is."+sumPrice+", the delivery fee is."+deliCharge+"The total amount is."+(sumPrice+deliCharge));
// Add data to the array
names[i]=name;
dishMegs[i]=dishMeg;
times[i]=time;
addresses[i]=address;
sumPrices[i]=sumPrice+deliCharge;
// The loop ends immediately after adding to the current loop
break; }}// If no empty seat is found at the end of the loop, the current bag is full
if(! isAdd){ System.out.println("Sorry, the dinner bag is full!");
}
Copy the code
5. Sign and order:
for (int i = 0; i <names.length; i++) {
// Check -- If the user information is empty, the order will not be printed
if(names[i]! =null){
String state=(states[i]==0)?"Booked":"Done";
String sumPrice=sumPrices[i]+"Yuan";
String time=times[i]+"When";
System.out.println((i+1) +" \t\t"+names[i]+" \t\t"+dishMegs[i]+" \t\t"+time
+" \t\t"+addresses[i]+" \t\t"+sumPrice+" \t\t"+state); }}Copy the code
6. Delete order:
for (int i = 0; i < names.length; i++) {
if(names[i]! =null&&states[i]==1&&delId==i+1) {// The order can be found and deleted
isDelFind=true;
// Perform the delete operation, all data after the deleted element is moved in sequence -- subsequent data
for (int j = delId-1; j < names.length-1; j++) {
names[j]=names[j+1];
dishMegs[j]=dishMegs[j+1];
times[j]=times[j+1];
addresses[j]=addresses[j+1];
states[j]=states[j+1];
}
// The last data is cleared and restored
names[names.length-1] =null;
dishMegs[dishMegs.length-1] =null;
times[times.length-1] =0;
addresses[addresses.length-1] =null;
states[states.length-1] =0;
System.out.println("Order deleted successfully!");
break;
}else if(names[i]! =null&&states[i]==0&&delId==i+1) {// Order can be found but cannot be deleted
isDelFind=true;
System.out.println("This order has not been signed and cannot be deleted!");
break; }}// If the order is not found at the end of the loop, it does not exist
if(! isDelFind){ System.out.println("The order you want to delete does not exist!");
}
Copy the code
7. I like it:
for (int i = 0; i < dishNames.length; i++) {
String price=prices[i]+"Yuan";
String praiseNum=(praiseNums[i]>0)? praiseNums[i]+"Praise":"";
System.out.println((i+1) +"\t "+dishNames[i]+"\t "+price+"\t "+praiseNum);
}
System.out.println("Please enter the number of the food you want to like.");
int praiseId=input.nextInt();
// Increase the number of likes
praiseNums[praiseId-1] + +; System.out.println("Thumbs up!");
Copy the code
Note:
Article for the core code, if you need a complete code, you can talk about me at any time, you can also add the penguin group 720994366 to find management to.