<details> <summary>标题</summary>
import java.util.Scanner;</details> 标签:tables,System,getOrder,测试,Table,table,out From: https://www.cnblogs.com/hz-blogs/p/17359551.html
import java.time.*;
public class Main{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Table tables[] = new Table[0]; //设置一个餐桌对象数组
Menu menu = new Menu(); //创建一个菜单类
String s = in.nextLine();
while(s.indexOf("table")==-1) { //更新菜单
menu.updateMenu(s);
s = in.nextLine();
if(s.equals("end"))
System.exit(0);
}
while(s.indexOf("end")==-1) { //订单处理
Table table = new Table();
table.setDateTime(s);
System.out.println("table "+table.getNum()+": ");
s = in.nextLine();
while(s.indexOf("table")==-1&&s.indexOf("end")==-1&&s.split(" ").length==2) { //判断菜品是否更新
menu.updateMenu(s);
s = in.nextLine();
}
int count = 0,count1 = 0;
while(s.indexOf("table")==-1&&s.indexOf("end")==-1) { //判断是否进行下一个订单或结束
if(s.indexOf("delete")!=-1) {
table.getOrder().deleteRecord(s,menu);
}else {
if(s.split(" ").length==4) {
table.getOrder().updateRecord(s);
if(table.getOrder().getRecord(count).getExit()==1)
System.out.println(table.getOrder().getRecord(count).getOrderNum()+" "+table.getOrder().getRecord(count).getD().getName()
+" "+table.getOrder().getRecord(count).getPrice1());
else
System.out.println(table.getOrder().getRecord(count).getName()+" does not exist");
count++;
}
else {
table.getOrder().updateOtherRecord(s); //更新餐桌信息
if(table.getOrder().getOtherRecord(count1).getExit()==1)
System.out.println(table.getOrder().getOtherRecord(count1).getOrderNum()+" table "+
table.getNum()+" pay for table "+table.getOrder().getOtherRecord(count1).getTableNum()
+" "+table.getOrder().getOtherRecord(count1).getPrice1());
else
System.out.println(table.getOrder().getOtherRecord(count1).getName()+" does not exist");
}
}
s = in.nextLine();
}
table.setTotal();
tables = Main.updateTables(tables,table);
}
if(tables!=null) {
for(int i =0;i<tables.length;i++)
if(!tables[i].checkOrderTime())
System.out.println("table "+tables[i].getNum()+" out of opening hours");
else
System.out.println("table "+tables[i].getNum()+": "+
tables[i].getTotal());
}
}
public static Table[] updateTables(Table []tables,Table table) { //在餐桌类数组中加入对象
int num = 0;
if(tables!=null)
num = tables.length;
Table []tables1 = new Table[num+1]; //更新桌信息
for(int i = 0;i<num;i++) {
tables1[i] = tables[i];
}
tables1[num] = table;
return tables1;
}
// public static Dish setNamePrice(String s) { //添加菜品
// String [] str = s.split(" ");
// String name = str[0];
// int price = Integer.parseInt(str[1]);
// Dish dish = new Dish(name,price);
// return dish;
// }
}