欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

吃货联盟订餐系统

程序员文章站 2022-06-28 17:54:24
java简易餐馆订单系统package chihuoxitong;import java.util.Scanner;public class index {public static void main(String[] args) {// TODO Auto-generated method stubString[] names=new String[4]; //点单人员名单String[] dishMegs=new String[4]; //选择菜品信息...

java简易餐馆订单系统

package chihuoxitong;

import java.util.Scanner;
public class index {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	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];     //总金额
	String[] dishNames= {"红烧带鱼","鱼香肉丝","时令鲜蔬"};	//菜品名称
	double[] prices=new double[] {38.0,20.0,10.0};      //菜品单价
	int[]praiseNums=new int[3];                         //点赞数
	
	names[0]="张三";          //存储订单,调试
	dishMegs[0]="鱼香肉丝两份";
	times[0]=14;
	addresses[0]="学院";
	sumPrices[0]=61.7;
	states[0]=1;
			
	Scanner input=new Scanner(System.in);  
	int num=-1;
	boolean isExit=false;
	System.out.println("欢迎使用使用吃货联盟订餐系统");

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("
”);
System.out.println(“请选择”);
String chose=input.next();
while(!(“1”.equals(chose)||“2”.equals(chose)||“3”.equals(chose)||“4”.equals(chose)||“5”.equals(chose)||“6”.equals(chose))) {

	System.out.println("输入有误请重新输入");
	chose=input.next();
}
int choose =Integer.parseInt(chose);//避免输入非法字符导致程序异常
switch (choose) {
case 1://点餐功能
	    System.out.println("****点餐****");
for(int i=0;i<names.length;i++) {
		if(names[i]==null) {
	System.out.println("请输入姓名");
	String name=input.next();//保存点单人员
	System.out.println("序号"+"\t"+"菜名"+"\t"+"\t"+"价格"+"\t"+"点赞");
	          for(int j=0;j<dishNames.length;j++)
	          {
		      System.out.println((j+1)+"\t"+dishNames[j]+"\t"+"\t"+prices[j]+"\t"+praiseNums[j]);	//菜单列表		
	          }
	System.out.println("请选择你想要的菜品的序号");
	int dishMeg=0;
				  do{
				      if(input.hasNextInt()) {
				    dishMeg=input.nextInt();
				       break;
				     }else {
				    input.next();
				    System.out.println("输入错误,请重新输入");
				          }
				    }while(true);
	  while (dishMeg<1||dishMeg>3) {
             System.out.println("菜品序号有误,请重新输入");
            dishMeg=input.nextInt();				
      						   }
	    System.out.println("请选择份数");
	       int timees=0;
	               do{
	            	if(input.hasNextInt()) {
	            		timees=input.nextInt();
	            		break;
	            		}else {
	            			input.next();
	    	            System.out.println("输入错误,请重新输入");
	            		}
	                  }while(true);
	     System.out.println("请您在10:00到20:00选择一个整点送餐");
	    int time=0;
	                do{
	    	         if(input.hasNextInt()) {
	    		      time=input.nextInt();
	    		      break;
	                   }else {
	     	           input.next();
	    	            System.out.println("输入错误,请重新输入");
	                    }
	                   }while(true);
         while (time<10||time>20) {
             System.out.println("时间有误,请重新输入");
             time=input.nextInt();				
         						   }
	      System.out.println("请输入送餐地址");
	      String address=input.next();
	   double price =prices[dishMeg-1]*timees;
	   double exprice=prices[dishMeg-1]*timees>50?0:5;
	  
	   //显示点单信息
	   System.out.println("点餐成功");
          System.out.print("您定的是:"+dishNames[dishMeg-1]+ "\n"+"送餐时间:"+time +"\n"+"送餐地点:"+address +"\n"+"餐费:"+ price+"\n"+"送餐费:"+exprice +"\n"+"总费用:"+(price+exprice) +"\n");		   
	 
          names[i]=name;
          dishMegs[i]=dishNames[i]+timees+"份";
          times[i]=time;
          addresses[i]=address;
          sumPrices[i]=price+exprice;
          states [i] =0;         //保存订单信息           
          break;		   
		}else if (names[names.length-1]!=null) {
			System.out.println("餐袋已满");
		}
			
	}
	break;
case 2://查看餐袋
	System.out.println("****查看餐袋****");
	System.out.println("单号"+"\t"+"订餐人"+"\t"+"餐品信息"+"\t"+"\t"+"送餐时间"+"\t"+"送餐地址"+"\t"+"总金额"+"\t"+"订单状态");
	for(int i=0;i<names.length;i++){
		if(names[i]!=null) {
		System.out.println((i+1)+"\t"+names[i]+"\t"+ dishMegs[i]+"\t"+times[i]+"\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+states[i]);
	}else if(names[0]==null) {
		System.out.println("没有订单信息");
		break;
	}
		}
	break;
case 3://签收订单
	System.out.println("****签收****");
	System.out.println("请选择要签收的单号");
	System.out.println("单号"+"\t"+"订餐人"+"\t"+"餐品信息"+"\t"+"\t"+"送餐时间"+"\t"+"送餐地址"+"\t"+"总金额"+"\t"+"订单状态");
	for(int i=0;i<names.length;i++){
		if(names[i]!=null) {
		System.out.println((i+1)+"\t"+names[i]+"\t"+ dishMegs[i]+"\t"+times[i]+"\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+states[i]);
	}else if(names[0]==null){
		System.out.println("目前没有订单信息");
		break;
	}
		}
	int s;
    do{
    	if(input.hasNextInt()) {
    		s=input.nextInt();
    		break;
    }else {
    	input.next();
    	System.out.println("输入错误,请重新输入");
          }
    }while(true);
	
		if( states [s-1] ==0&&names[s-1]!=null) {
			states[s-1]=1;
			System.out.println("订单签收成功");
			
		}else if(states [s-1] ==1&&names[s-1]!=null){
			
			System.out.println("订单已经签收,不能再次签收");
			
		}else {
			System.out.println("订单不存在,不可签收");
			
				
	}
	break;
case 4://删除订单
	System.out.println("****删除订单****");
	System.out.println("请输入要删除的订单号");
	System.out.println("单号"+"\t"+"订餐人"+"\t"+"餐品信息"+"\t"+"\t"+"送餐时间"+"\t"+"送餐地址"+"\t"+"总金额"+"\t"+"订单状态");
	for(int i=0;i<names.length;i++){
		if(names[i]!=null) {
		System.out.println((i+1)+"\t"+names[i]+"\t"+ dishMegs[i]+"\t"+times[i]+"\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+states[i]);
	}else if(names[0]==null) {
		System.out.println("没有订单信息");
		break;
	}
		}
	int Order=0;
    do{
    	if(input.hasNextInt()) {
    		 Order=input.nextInt();
    		break;
    }else {
    	input.next();
    	System.out.println("输入错误,请重新输入");
          }
    }while(true);
	for(int i=1;i<=names.length;i++) {
		if(Order==i&&states [i-1] ==1&&names[i-1]!=null) {
			for(int j=Order-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];
				 sumPrices[j]=sumPrices[j+1];
				 states[j]= states[j+1];
			}
			names[names.length-1]=null;
			 dishMegs[names.length-1]= null;
			 times[names.length-1]=0;
			 addresses[names.length-1]=null;
			 sumPrices[names.length-1]=0;
			 states[names.length-1]= 0;
			 System.out.println("删除订单成功");
			 break;
		}else if (Order==i&&states [i-1] ==0&&names[i-1]!=null) {
			System.out.println("订单未签收,不能删除!");
			break;				
		}else {
			System.out.println("单号信息错误");
			break;
		}
		
	}
	break;
case 5://点赞
	System.out.println("****点赞系统****");		
	System.out.println("此功能需要对用户信息进行确认,请输入您的名字");
	boolean a=false;
	
		String message=input.next();
	
		for (int i = 0; i < names.length; i++) {		
		if (message.equals(names[i])) {
			System.out.println("验证成功,您可以继续操作");
			a=true;
			}
}
		if(!a) {
	System.out.println("信息错误,将退出此功能");
	break;
}			
	System.out.println("序号"+"\t"+"菜名"+"\t"+"价格"+"\t"+"点赞");
	for(int j=0;j<dishNames.length;j++)
	{
		System.out.println((j+1)+"\t"+dishNames[j]+"\t"+prices[j]+"\t"+praiseNums[j]);	//菜单列表		
	}
	System.out.println("请输入你想要的点赞的菜品");
	int puls=0;
	do{
    	if(input.hasNextInt()) {
    		puls=input.nextInt();
    		break;
    }else {
    	input.next();
    	System.out.println("输入错误,请重新输入");
          }
    }while(true);
	for(int i=0;i<dishNames.length;i++) {
		if(dishNames[puls-1]==dishNames[i]) {
			praiseNums[i]=praiseNums[i]+1;
			System.out.println("点赞成功");
			break;
		}				
	}		
	break;
case 6:
	System.out.println("退出功能");
	isExit=true;
	break;
default:
	break;
}
if(!isExit) {
	System.out.println("输入0返回");
	String chart=input.next();
	while(!"0".equals(chart)) {
		System.out.println("只有输入0才能返回哦!");
		chart=input.next();			
	}
	 num=Integer.parseInt(chart);
}else {
	break;
}

}while(num==0);
input.close();

}

}

本文地址:https://blog.csdn.net/wolailxiaotan/article/details/109572718

相关标签: java作业 java