本项目是作者在学习完Java基础之后练习的一个小项目,如下:
package eat; import java.util.Scanner; public class MeiTuan { public static void main(String[] args) { //首页展示 Scanner sc=new Scanner(System.in); String[]dishes= {"辣子鸡","麻辣龙虾","红烧肉","蒜泥花甲"}; int[]prices= {38,88,68,48}; String[][]bills=new String[1024][2]; System.out.println("****欢迎来到吃货联盟****"); int chose; int []honors=new int[1024]; do { System.out.println("************************"); System.out.println("1、我要订餐"); System.out.println("2、查看订单"); System.out.println("3、确认订单"); System.out.println("4、删除订单"); System.out.println("5、我要点赞"); System.out.println("6、退出系统"); System.out.println("************************"); chose=sc.nextInt(); switch(chose){ case 1: System.out.println("我要订餐"); System.out.print("请输入您的姓名:"); String name=sc.next(); System.out.println("序号 \t 菜名 \t\t 单价"); for (int i = 0; i < prices.length; i++) { System.out.println(i+1+" \t "+dishes[i]+ " \t "+prices[i]+"元"); } System.out.print("请输入您要点的菜名:"); int rank=sc.nextInt(); System.out.print("请选择份数:"); int pcs=sc.nextInt(); System.out.print("请输入配送地址:"); String address=sc.next(); int time; do { System.out.print("请输入您的送餐时间(10-20点整点):"); time=sc.nextInt(); if(time<10 || time>20) { System.out.println("不在配送时间,请重新输入!"); } }while(time<10 || time>20); int total=prices[rank-1]*pcs; total=total>50?total:total+6;//三元表达式 System.out.println("尊敬的"+name+" 您点了"+pcs+"份"+dishes[rank-1]+ " 价格为:"+total+"元 将于"+time+"点送达,请注意查收!"); for (int i = 0; i < bills.length; i++) { if (bills[i][1]==null) { bills[i][0]=dishes[rank-1]+"\t"+pcs+ "\t"+total+"\t"+name+"\t"+address+"\t"+time; bills[i][1]="已预订"; break; } if(i==bills.length-1) { System.out.println("订单已满,请下次再来!"); } } System.out.print("输入0返回"); chose=sc.nextInt(); break; case 2: System.out.println("查看订单"); System.out.println ("序号 \t 菜名 \t 份数 \t 总价 \t 姓名 \t 地址 \t 时间 \t 状态"); for (int i = 0; i < bills.length; i++) { if(bills[i][1]==null) { break; } System.out.println(i+1+" \t "+bills[i][0]+" \t "+bills[i][1]); } System.out.print("输入0返回"); chose=sc.nextInt(); break; case 3: System.out.println("确认订单"); System.out.println ("序号 \t 菜名 \t 份数 \t 总价 \t 姓名 \t 地址 \t 时间 \t 状态"); for (int i = 0; i < bills.length; i++) { if(bills[i][1]==null) { break; } System.out.println(i+1+" \t "+bills[i][0]+" \t "+bills[i][1]); } System.out.print("请输入要确认的订单编号:"); int confirm=sc.nextInt(); if(bills[confirm-1][1]==null) { System.out.println("订单不存在,订单确认失败!"); }else if(!bills[confirm-1][1].equals("已预订")) { System.out.println("订单已完成,不能重复确认!"); }else { bills[confirm-1][1]="已完成"; System.out.println("签收成功!"); } System.out.print("输入0返回"); chose=sc.nextInt(); break; case 4: System.out.println("删除订单"); System.out.println ("序号 \t 菜名 \t 份数 \t 总价 \t 姓名 \t 地址 \t 时间 \t 状态"); for (int i = 0; i < bills.length; i++) { if(bills[i][1]==null) { break; } System.out.println(i+1+" \t "+bills[i][0]+" \t "+bills[i][1]); } System.out.print("请输入要删除的订单编号:"); int delete=sc.nextInt(); if(delete<1 || delete>1024) { System.out.println("输入错误!"); }else if(bills[delete-1][1]==null) { System.out.println("订单不存在!"); }else if(!bills[delete-1][1].equals("已完成")) { System.out.println("未完成订单不能删除!"); }else { for (int i =delete; i < bills.length; i++) { bills[i-1][0]=bills[i][0]; bills[i-1][1]=bills[i][1]; if(bills[i][1]==null) { break; } } } System.out.print("输入0返回"); chose=sc.nextInt(); break; case 5: System.out.println("我要点赞"); System.out.println("序号 \t 菜名 \t\t 单价 \t 点赞数"); for (int i = 0; i < dishes.length; i++) { System.out.println (i+1+" \t "+dishes[i]+" \t "+prices[i]+" 元\t "+honors[i]); } System.out.println("请输入您要点赞的菜品序号:"); int honor=sc.nextInt(); if(honor<1 || honor>dishes.length) { System.out.println("输入有误!"); }else { honors[honor-1]++; System.out.println (dishes[honor-1]+"点赞成功,赞数变味:"+honors[honor-1]); } System.out.println(); System.out.print("输入0返回"); chose=sc.nextInt(); break; case 6: System.out.println("退出系统"); break; default: System.out.println("输入错误!"); chose=-1; } }while(chose==0); System.out.println("欢迎下次再来!"); } }