吃货联盟

InitArray()  类:

 

 


static Menu[] menu1 = new Menu[100];
static Order[] order1 = new Order[100];

Scanner scanner=new Scanner(System.in);

static
{

menu1[0] = new Menu();
menu1[0].setId(1);
menu1[0].setName("红烧鱼1");
menu1[0].setPrice(32);
menu1[0].setEvaluate(0);


menu1[1] = new Menu();
menu1[1].setId(2);
menu1[1].setName("红烧鱼2");
menu1[1].setPrice(34);
menu1[1].setEvaluate(0);

menu1[2] = new Menu();
menu1[2].setId(3);
menu1[2].setName("红烧鱼3");
menu1[2].setPrice(32);
menu1[2].setEvaluate(0);


}
public void showMenu(){
int num=0;
System.out.println("***我要订餐***");
System.out.println("请输入订餐人姓名:");
for (int i=0;i<InitArray.order1.length;i++){
if (InitArray.order1[i]==null){
InitArray.order1[i]=new Order();
InitArray.order1[i].setId(i+1);
InitArray.order1[i].setName(scanner.next());
num=i;
break;
}
}

System.out.println("序号" + "\t" + "菜名" + "\t" + "单价" );
for (Menu item : InitArray.menu1) {
if (item!=null){
System.out.println(item.getId() + "\t" + item.getName() + "\t" + item.getPrice());
}
}
System.out.println("请输入你要点的菜品编号");
int id=scanner.nextInt();
String foodName="";
double price=0;
for (Menu item : menu1) {
if (item.getId()==id){
foodName=item.getName();
price=item.getPrice();
break;
}
}
System.out.println("请输入选择份数:");
Integer sum=scanner.nextInt();
InitArray.order1[num].setInfo(foodName+" "+sum+"份");

System.out.println("请输入送餐时间(送餐时间是从10点到20点整点):");
InitArray.order1[num].setDate(scanner.nextInt());

System.out.println("请输入送餐地址:");
InitArray.order1[num].setAdress(scanner.nextLine());

 

 

 

 

InitArray.order1[num].setPrice(sum*price);
InitArray.order1[num].setOrderState(OrderState.已预订);
System.out.println("订餐成功");

System.out.println("您订的是"+InitArray.order1[num].getInfo());
System.out.println("送餐时间"+InitArray.order1[num].getDate()+"点");
System.out.println("餐费"+InitArray.order1[num].getPrice()+",送餐费0元,总计"+InitArray.order1[num].getPrice());

}

 

 

 

创建初始化类:

为后续的java赋值:

 

 

 

posted @ 2017-05-09 14:53  liuzhe01  阅读(171)  评论(0编辑  收藏  举报