Initialization :
public class OrderingSet {
String[]names=new String[4];
String[]dishMegs=new String[4];
int[]times=new int[4];
String[]addresses=new String[4];
int[]states=new int[4];
double[]sumPrices=new double[4];
}
Test categories:
public class OrderingMgr {
public static void main(String[] args) {
OrderingUtil util=new OrderingUtil();
util.menu();
}
}
Main code:
import java.util.Scanner;
OrderingUtil class {public
String [] = {dishname "braised octopus", "fish-flavored shredded pork", "season fresh vegetables"};
Double [] = new new Double Prices [] {} 38.0,20.0,10.0;
int [] praiseNums new new int = [. 3];
Scanner Scanner new new INPUT = (the System.in);
OrderingSet new new OrderingSet OST = ();
public void MENU () {
Boolean = inBig to false;
int LIN = -1;
int NUM = 0;
the System. out.println ( "Welcome" to eat and Monetary Union reservation system "");
do {
System.out.println ( "************************************************************ **************** ");
System.out.println (." I want to ordering 1 \ n2 view meal bags \ n3 sign orders \ n4 delete orders \ n5.... I'll have praised \ n6 exit the system ");.
System.out.println (" *****************************************");
System.out.println ( "Select:");
IF (input.hasNextInt () == to true) {
NUM = input.nextInt ();
Switch (NUM) {
Case. 1:
System.out.println ( "** * I would like to ordering *** ");
the Table ();
BREAK;
Case 2:
System.out.println (" food bags *** View *** ");
menuInitial ();
BREAK;
Case 3:
System.out .println ( "*** sign orders ***");
qian ();
BREAK;
4 Case:
System.out.println ( "Delete Orders *** ***");
the Delete ();
BREAK;
Case 5:
System.out.println ( "*** I'll have praised ***");
like ();
BREAK;
Case 6:
System.out.println ( "*** exit the system ***");
System.out.println ( "! Thank you, welcome to the next visit");
inBig = to true;
BREAK;
default:
System.out.println ( "input errors, please re-enter:");
menu();
= to true inBig;
BREAK;
}
IF {(inBig!)
System.out.println ( "Input return 0:");
LIN = input.nextInt ();
} the else {
BREAK;
}
} the else {
System.out.println ( "You is not a number");
String [] = {dishname "braised octopus", "fish-flavored shredded pork", "season fresh vegetables"};
Double [] = new new Double Prices [] {} 38.0,20.0,10.0;
int [] praiseNums new new int = [. 3];
Scanner Scanner new new INPUT = (the System.in);
OrderingSet new new OrderingSet OST = ();
public void MENU () {
Boolean = inBig to false;
int LIN = -1;
int NUM = 0;
the System. out.println ( "Welcome" to eat and Monetary Union reservation system "");
do {
System.out.println ( "************************************************************ **************** ");
System.out.println (." I want to ordering 1 \ n2 view meal bags \ n3 sign orders \ n4 delete orders \ n5.... I'll have praised \ n6 exit the system ");.
System.out.println (" *****************************************");
System.out.println ( "Select:");
IF (input.hasNextInt () == to true) {
NUM = input.nextInt ();
Switch (NUM) {
Case. 1:
System.out.println ( "** * I would like to ordering *** ");
the Table ();
BREAK;
Case 2:
System.out.println (" food bags *** View *** ");
menuInitial ();
BREAK;
Case 3:
System.out .println ( "*** sign orders ***");
qian ();
BREAK;
4 Case:
System.out.println ( "Delete Orders *** ***");
the Delete ();
BREAK;
Case 5:
System.out.println ( "*** I'll have praised ***");
like ();
BREAK;
Case 6:
System.out.println ( "*** exit the system ***");
System.out.println ( "! Thank you, welcome to the next visit");
inBig = to true;
BREAK;
default:
System.out.println ( "input errors, please re-enter:");
menu();
= to true inBig;
BREAK;
}
IF {(inBig!)
System.out.println ( "Input return 0:");
LIN = input.nextInt ();
} the else {
BREAK;
}
} the else {
System.out.println ( "You is not a number");
BREAK;
}
} the while (LIN == 0);
}
// Check food bags
public void menuInitial () {
System.out.println ( "ID \ t \ t ordering person \ t \ t food products information \ t \ t send meal time \ t \ t delivery address \ t \ t the total amount of \ t \ t ordering state ");
for (int I = 0; I <ost.names.length; I ++) {
IF (ost.names [I] ! = null) {
String = State (ost.states [i] == 0) "reserved":? "completed";
String = ost.times DATE [i] + "point";
String sumPrice = ost.sumPrices [i] + "element";
System.out.println ((I +. 1) + "\ T \ T" + ost.names [i] + "\ T \ T" + ost.dishMegs [i] + "\ t \ t "+ date +" \ t \ t \ t "+ ost.addresses [i] +" \ t \ t \ t "+ sumPrice +" \ t \ t "+ state);
}
}
}
// I ordering
public Boolean Table () {
Boolean = isAdd to false;
for (int J = 0; J <ost.names.length; J ++) {
IF (ost.names [J] == null) {
isAdd to true = ;
System.out.println ( "Please enter the person's name ordering:");
String name = input.next ();
System.out.println ( "number \ t \ t Dishes \ t \ t \ t Price \ t \ Like t-point number ");
for (int I = 0; I <dishName.length; I ++) {
String. price Prices = [I] +" element ";
String priaiseNum = (praiseNums [I])>? 0 praiseNums [I ] + "Like": "0";
System.out.println ((I +. 1) + "\ T \ T" + dishname [I] + "\ T \ T". price + + "\ T \ T" + priaiseNum );
}
System.out.println ( "Please select your dishes point number:");
int pwed = input.nextInt ();
System.out.println ( "Please select the number of copies you want");
int = input.nextInt the Test ();
String dishMg = dishname [-pwed. 1] + "" + + Test "parts";
Double sumPrice = Prices [-pwed. 1] * Test;
System.out.println ( "Please enter the delivery time (delivery time 10:00 o'clock to 20 o'clock room): ");
int = input.nextInt Time ();
the while (Time <10 || Time> 20 is) {
System.out.println (" you make a mistake, enter ! integer between 10-20 ");
Time = input.nextInt ();
}
System.out.println (" Please enter the delivery address: ");
String add=input.next();
System.out.println ( "ordering success!");
System.out.println ( "Your order is:" + dishMg);
System.out.println ( "Room Time:" + time + "point");
IF (sumPrice <50) {
Double deliCharge = 5.0;
System.out.println ( "meals:" + sumPrice + "element, send meals:" + deliCharge + "yuan, Total:" + (sumPrice + deliCharge) + " yuan" );
ost.names [J] = name;
ost.dishMegs [J] = dishMg;
ost.times [J] = Time;
ost.addresses [J] = the Add;
ost.sumPrices [J] + = sumPrice deliCharge;
BREAK ;
} the else {
System.out.println ( "meals:" + sumPrice + "element, send meals:" + "0" + "Yuan, Total:" + sumPrice + "meta");
ost.names [J] = name;
OST. dishMegs [J] = dishMg;
ost.times [J] = Time;
ost.addresses [J] = the Add;
ost.sumPrices [J] = sumPrice;
BREAK;
}
}
}
IF {(isAdd!)
System.out.println ( "Sorry, your meal bags full!");
return false;
} the else {
return to true;
}
}
// sign orders
public void qian () {
= isFind to false Boolean;
System.out.println ( "Please select a sign order number:");
int input.nextInt = SUM ();
for (int I = 0; I <ost.names.length; I ++) {
IF (ost.names [I] = null && ost.states [I] == I == 0 && SUM +. 1!) {
ost.states [I] =. 1;
System.out.println ( "Order receipt success!");
isFind to true =;
} the else IF (ost.names [I] = null && ost.states [I] == I == + SUM. 1. 1 &&!) {
System.out.println ( "your order is complete select sign, not sign again! ");
isFind = to true;
}
}
! IF (isFind) {
System.out.println (" You choose the order does not exist ")!;
}
}
// delete orders
public void delete(){
boolean isDe=false;
System.out.println("请输入要删除的订单:");
int order=input.nextInt();
for (int i=0;i<ost.names.length;i++){
if (ost.names[i]!=null&&ost.states[i]==1&&order==i+1){
isDe=true;
for (int j=0;j>ost.names.length;j++){
ost.names[j]=ost.names[j+1];
ost.dishMegs[j]=ost.dishMegs[j+1];
ost.times[j]=ost.times[j+1];
ost.addresses[j]=ost.addresses[j+1];
ost.states[j]=ost.states[j+1];
ost.sumPrices[j]=ost.sumPrices[j+1];
}
Int = ost.names.length-endIndex. 1;
ost.names [endIndex] = null;
ost.dishMegs [endIndex] = null;
ost.times [endIndex] = 0;
ost.addresses [endIndex] = null;
OST. States [endIndex] = 0;
ost.sumPrices [endIndex] = 0;
System.out.println ( "delete line success!");
BREAK;
!} the else IF (ost.names [I] = null && ost.states [I] the Order == 0 && i == + 1) {
System.out.println ( "you choose not to sign the order can not be deleted!");
ISDe = to true;
BREAK;
}
}
IF (! isDe) {
System.out.println ( "you want to delete the order does not exist!");
}
}
// I'll have like
public void like () {
System.out.println ( "Number \ t \ t Dishes \ t \ t Price ");
for (int I = 0; I <dishName.length; I ++) {
String. price dishname = [I] +" element ";
String priaiseNum = (praiseNums [I])>? 0 praiseNums [I] +" Like ":" ";
System.out.println ((I +. 1) +" \ T \ T "+ dishname [I] +" \ T \ T ". price + +" \ T \ T "+ priaiseNum);
}
the System. out.println ( "Please select your points praise dishes numbers:");
int Bum = input.nextInt ();
praiseNums [Bum-1] ++;
System.out.println ( "thumbs up success!");
}
}
} the while (LIN == 0);
}
// Check food bags
public void menuInitial () {
System.out.println ( "ID \ t \ t ordering person \ t \ t food products information \ t \ t send meal time \ t \ t delivery address \ t \ t the total amount of \ t \ t ordering state ");
for (int I = 0; I <ost.names.length; I ++) {
IF (ost.names [I] ! = null) {
String = State (ost.states [i] == 0) "reserved":? "completed";
String = ost.times DATE [i] + "point";
String sumPrice = ost.sumPrices [i] + "element";
System.out.println ((I +. 1) + "\ T \ T" + ost.names [i] + "\ T \ T" + ost.dishMegs [i] + "\ t \ t "+ date +" \ t \ t \ t "+ ost.addresses [i] +" \ t \ t \ t "+ sumPrice +" \ t \ t "+ state);
}
}
}
// I ordering
public Boolean Table () {
Boolean = isAdd to false;
for (int J = 0; J <ost.names.length; J ++) {
IF (ost.names [J] == null) {
isAdd to true = ;
System.out.println ( "Please enter the person's name ordering:");
String name = input.next ();
System.out.println ( "number \ t \ t Dishes \ t \ t \ t Price \ t \ Like t-point number ");
for (int I = 0; I <dishName.length; I ++) {
String. price Prices = [I] +" element ";
String priaiseNum = (praiseNums [I])>? 0 praiseNums [I ] + "Like": "0";
System.out.println ((I +. 1) + "\ T \ T" + dishname [I] + "\ T \ T". price + + "\ T \ T" + priaiseNum );
}
System.out.println ( "Please select your dishes point number:");
int pwed = input.nextInt ();
System.out.println ( "Please select the number of copies you want");
int = input.nextInt the Test ();
String dishMg = dishname [-pwed. 1] + "" + + Test "parts";
Double sumPrice = Prices [-pwed. 1] * Test;
System.out.println ( "Please enter the delivery time (delivery time 10:00 o'clock to 20 o'clock room): ");
int = input.nextInt Time ();
the while (Time <10 || Time> 20 is) {
System.out.println (" you make a mistake, enter ! integer between 10-20 ");
Time = input.nextInt ();
}
System.out.println (" Please enter the delivery address: ");
String add=input.next();
System.out.println ( "ordering success!");
System.out.println ( "Your order is:" + dishMg);
System.out.println ( "Room Time:" + time + "point");
IF (sumPrice <50) {
Double deliCharge = 5.0;
System.out.println ( "meals:" + sumPrice + "element, send meals:" + deliCharge + "yuan, Total:" + (sumPrice + deliCharge) + " yuan" );
ost.names [J] = name;
ost.dishMegs [J] = dishMg;
ost.times [J] = Time;
ost.addresses [J] = the Add;
ost.sumPrices [J] + = sumPrice deliCharge;
BREAK ;
} the else {
System.out.println ( "meals:" + sumPrice + "element, send meals:" + "0" + "Yuan, Total:" + sumPrice + "meta");
ost.names [J] = name;
OST. dishMegs [J] = dishMg;
ost.times [J] = Time;
ost.addresses [J] = the Add;
ost.sumPrices [J] = sumPrice;
BREAK;
}
}
}
IF {(isAdd!)
System.out.println ( "Sorry, your meal bags full!");
return false;
} the else {
return to true;
}
}
// sign orders
public void qian () {
= isFind to false Boolean;
System.out.println ( "Please select a sign order number:");
int input.nextInt = SUM ();
for (int I = 0; I <ost.names.length; I ++) {
IF (ost.names [I] = null && ost.states [I] == I == 0 && SUM +. 1!) {
ost.states [I] =. 1;
System.out.println ( "Order receipt success!");
isFind to true =;
} the else IF (ost.names [I] = null && ost.states [I] == I == + SUM. 1. 1 &&!) {
System.out.println ( "your order is complete select sign, not sign again! ");
isFind = to true;
}
}
! IF (isFind) {
System.out.println (" You choose the order does not exist ")!;
}
}
// delete orders
public void delete(){
boolean isDe=false;
System.out.println("请输入要删除的订单:");
int order=input.nextInt();
for (int i=0;i<ost.names.length;i++){
if (ost.names[i]!=null&&ost.states[i]==1&&order==i+1){
isDe=true;
for (int j=0;j>ost.names.length;j++){
ost.names[j]=ost.names[j+1];
ost.dishMegs[j]=ost.dishMegs[j+1];
ost.times[j]=ost.times[j+1];
ost.addresses[j]=ost.addresses[j+1];
ost.states[j]=ost.states[j+1];
ost.sumPrices[j]=ost.sumPrices[j+1];
}
Int = ost.names.length-endIndex. 1;
ost.names [endIndex] = null;
ost.dishMegs [endIndex] = null;
ost.times [endIndex] = 0;
ost.addresses [endIndex] = null;
OST. States [endIndex] = 0;
ost.sumPrices [endIndex] = 0;
System.out.println ( "delete line success!");
BREAK;
!} the else IF (ost.names [I] = null && ost.states [I] the Order == 0 && i == + 1) {
System.out.println ( "you choose not to sign the order can not be deleted!");
ISDe = to true;
BREAK;
}
}
IF (! isDe) {
System.out.println ( "you want to delete the order does not exist!");
}
}
// I'll have like
public void like () {
System.out.println ( "Number \ t \ t Dishes \ t \ t Price ");
for (int I = 0; I <dishName.length; I ++) {
String. price dishname = [I] +" element ";
String priaiseNum = (praiseNums [I])>? 0 praiseNums [I] +" Like ":" ";
System.out.println ((I +. 1) +" \ T \ T "+ dishname [I] +" \ T \ T ". price + +" \ T \ T "+ priaiseNum);
}
the System. out.println ( "Please select your points praise dishes numbers:");
int Bum = input.nextInt ();
praiseNums [Bum-1] ++;
System.out.println ( "thumbs up success!");
}