为了账号安全,请及时绑定邮箱和手机立即绑定

麻辣烫点餐系统,请多指教

标签:
Java

//菜单类
package haoyunlai;
public class Menu implements Comparable<Menu> {
public String order;//序号
public String name;//菜名
public String money;//价格
public int number;//个数
public Menu(){

}
public void setNumber(int number){
this.number=number;
}
public Menu( String name,String money){
this.name=name;
this.money=money;
this.number=getNumber();
}

public int getNumber(){
    return number;
}

//@Override
public int compareTo(Menu o) {
// TODO Auto-generated method stub
double x,y;
x=Double.parseDouble(o.money);
y=Double.parseDouble(this.money);
if(y>x){
return 1;
}else{
if(y==x)
return 0;
else
return -1;
}

}

}
//顾客类
package haoyunlai;

import java.util.ArrayList;
import java.util.List;

public class People {
public String name;
public String cipher;
public List<Menu> menus;
public People(){

 }
 public People(String name,String cipher){
     this.name=name;
     this.cipher=cipher;
     this.menus=new ArrayList();
 }
 public String getName(){
     return name;
 }
 public String getCipher(){
     return cipher;
 }
 @Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((cipher == null) ? 0 : cipher.hashCode());
    result = prime * result + ((name == null) ? 0 : name.hashCode());
    return result;
}
@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    People other = (People) obj;
    if (cipher == null) {
        if (other.cipher != null)
            return false;
    } else if (!cipher.equals(other.cipher))
        return false;
    if (name == null) {
        if (other.name != null)
            return false;
    } else if (!name.equals(other.name))
        return false;
    return true;
}

}

//自定义异常类
package haoyunlai;

public class MyEx extends Exception {
int n;
MyEx(int n){
this.n=n;
}
public int getn(){
return n;
}

}
//主函数
package haoyunlai;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Order {
public Set<People> people;

public Order(){

    this.people=new HashSet();
    People p1=new People("Tom","123");
    People p2=new People("李四","1234");
    People p3=new People("王朝","1234");
    People p4=new People("马汉","1234");
    people.add(p1);
    people.add(p2);
    people.add(p3);
    people.add(p4);
}

//判断昵称是否被占用
public boolean PanDuan(String name){
boolean p=false;
for(People pe:people){
if(pe.name.equals(name)){
p=true;
break;
}
else {
p=false;
}
}

    return p;
}

//输入异常处理方法
public int Try(int i){
class B {

            public int Try(int n) throws MyEx{
                Scanner scan=new Scanner(System.in);
                int  x=scan.nextInt();
                if(x<0x>n){
                    MyEx ex=new MyEx(n);
                    throw(ex);//抛出异常
                }
                return x;

            }
        }
     B a=new B();
     int x=1000;
      while(true){
         try{ 
      x=a.Try(i);
     break;
         }
        catch(InputMismatchException e){
            System.out.println("输入有误,请输入正整数");
        }
         catch(MyEx e){
            System.out.println("输入有误,请输入1~"+e.getn()+"之间的正整数");
         }
      }
      return x;
      }

//注册会员
public void ZhuCe(){
while(true){
Scanner scan=new Scanner(System.in);
System.out.println("请问你是否为会员 1是 2不是");
int b=Try(2);
if(b==2){
System.out.println("请您先进行注册");
System.out.println("请输入昵称:");
String name=scan.next();
boolean p=PanDuan(name);
if(p){System.out.println("该昵称已被占用");
continue;}//判断该昵称是否被占用
String cipher;
while(true){
System.out.println("请输入密码");
cipher=scan.next();
System.out.println("请确认密码");
String cipher1=scan.next();
if(cipher.equals(cipher1)){
break;
}else{
System.out.println("您两次输入的密码不匹配,请确认后重新输入");
}
}
People peo=new People(name,cipher);
System.out.println("恭喜您注册成功");
people.add(peo);
System.out.println("欢迎"+peo.name);
break;
}else{
People peo;
while(true){
System.out.println("请输入您的昵称:");
String name=scan.next();
boolean p=PanDuan(name);
if(!p){System.out.println("您输入的昵称不正确");
continue;}//

         System.out.println("请输入您的密码:");
         String cipher=scan.next();
         peo=new People(name,cipher);

         boolean q= people.contains(peo);

         if(!q) {    System.out.println("您输入的密码不正确");
         continue;
         }
         else{
         System.out.println("欢迎"+peo.name);

         break;
         }

         }
         break;
         }}
 }

//菜单

public static void main(String[] args){
Order it=new Order();
Menu m=new Menu();
double sum=0;
List<Menu> menus=new ArrayList<Menu>();
Scanner scan=new Scanner(System.in);
System.out.println("欢迎来到好运来麻辣烫");
boolean p=true;

        it.ZhuCe(); 
       while(p){
        System.out.println("我们店内有以下4类食品类供您选择: 1主食   2蔬菜   3火锅料理    4 肉食   5油炸  6清单   7删除    8结账");

        System.out.println("您的选择是:");
        System.out.println("序号"+"\t"+"名称"+"\t"+"单价/元");
        int i=it.Try(9);
         switch(i){
         case 1:
             //主食
             System.out.println("主食类有:");
            List<Menu> menu1=new ArrayList<Menu>(); 
            Menu[] m1={new Menu("鸡蛋面","1.0"),new Menu("玉米面","1.5"),new Menu("蒜蓉排骨面","2.0"),new Menu("手工碗面","2.0"),new Menu("龙口粉丝","2.0"),new Menu("过桥米线","2.0"),new Menu("手拍拉面","2.0"),new Menu("QQ面","2.5"),   }; 
            menu1.addAll(Arrays.asList(m1));
            int size1=menu1.size();
            for(int j=0;j<size1;j++){
                System.out.println(j+1+"\t"+menu1.get(j).name+"\t"+menu1.get(j).money);
            }

            while(true){
                 System.out.println("是否需要添加主食? 1是    2不是");
                int b=it.Try(2);
                if(b==2){
                    break;
                }
               System.out.println("请输入您要选的主食:");
            int a=it.Try(size1+1)-1;
            System.out.println("请输入你要添加的个数:");
            int c=it.Try(9);
            menu1.get(a).number=c;
            menus.add(menu1.get(a));

            }
            continue;

         case 2:
            //小青菜、大白菜、木耳菜、土豆、南瓜、冬瓜、菠菜、荞麦菜、空心菜、香菜、红萝卜、豆腐、牛血、榨菜、油豆腐、豆腐干、千张、千张包、素机、素肉、花菜、海带、日本豆腐、西红柿、香菇、蘑菇、金珍菇,平菇、油条、油面
             System.out.println("蔬菜类有:");
             List<Menu> menu2=new ArrayList<Menu>();
             Menu[] m2={new Menu("鲜豆腐","0.5"),new Menu("土豆片","0.5"),new Menu("冬瓜","0.5"),new Menu("小青菜","1.0"), new Menu("小青菜","1.0"),new Menu("生菜","1.0"),new Menu("金针菇","1.0"),new Menu("香菇","1.5"),new Menu("空心菜","1.0"),   };
             menu2.addAll(Arrays.asList(m2));
             Collections.sort(menu2);
             int size2=menu2.size();
                for(int j=0;j<size2;j++){
                    System.out.println(j+1+"\t"+menu2.get(j).name+"\t"+menu2.get(j).money);
                }

                while(true){
                     System.out.println("是否需要继续添加蔬菜? 1是    2不是");
                    int b=it.Try(2);
                    if(b==2){
                        break;
                    }
                   System.out.println("请输入您要选的蔬菜:");
                int a=it.Try(size2+1)-1;

                System.out.println("请输入你要添加的个数:");
                int c=it.Try(9);
                menu2.get(a).number=c;
                menus.add(menu2.get(a));

                }
                continue;
         case 3:
            //贡丸、鱼丸、虾丸、牛肉丸、包心贡丸、包心鱼丸、开花肠、北海贝、里脊肉、热狗、骨肉相联、川香鸡柳、肘花卷、墨鱼棒、虾米饺等;
             System.out.println("火锅料理类有:");
             List<Menu> menu3=new ArrayList<Menu>();  
             Menu[] m3={new Menu("贡丸","0.75"), new Menu("鱼丸","0.75"),new Menu("牛肉丸","0.75"),new Menu("虾丸","0.75"),new Menu("虾米饺","0.75"),new Menu("年糕","1.0"),new Menu("油条","1.0"),new Menu("安井水晶包","0.75"),   };
                menu3.addAll(Arrays.asList(m3));
                Collections.sort(menu3);
                int size3=menu3.size();
                for(int j=0;j<size3;j++){
                    System.out.println(j+1+"\t"+menu3.get(j).name+"\t"+menu3.get(j).money);
                }

                while(true){
                     System.out.println("是否需要继续添加火锅料理? 1是    2不是");
                    int b=it.Try(2);
                    if(b==2){
                        break;
                    }
                   System.out.println("请输入您要选的火锅料理:");
                int a=it.Try(size3+1)-1;

                System.out.println("请输入你要添加的个数:");
                int c=it.Try(9);
                menu3.get(a).number=c;
                menus.add(menu3.get(a));
                }
                continue;
         case 4:
             //鸡蛋、煎鸡蛋、虾、鹌鹑蛋、鸡肠、牛肉、羊肉、牛肚,牛腩,鸡珍、鸡爪等
             System.out.println("肉食类有:");
            List<Menu> menu4=new ArrayList<Menu>(); 
             Menu[] m4={new Menu("鸡蛋","1.5"),new Menu("鹌鹑蛋","0.75"),new Menu("鸡爪","1.5"),new Menu("鸡翅","3.5"),new Menu("鸡腿","5.5"),};
                menu4.addAll(Arrays.asList(m4));
                Collections.sort(menu4);
                int size4=menu4.size();
                for(int j=0;j<size4;j++){
                    System.out.println(j+1+"\t"+menu4.get(j).name+"\t"+menu4.get(j).money);
                }

                while(true){
                     System.out.println("是否需要继续添加肉食? 1是    2不是");
                    int b=it.Try(2);
                    if(b==2){
                        break;
                    }
                   System.out.println("请输入您要选的肉食:");
                int a=it.Try(size4+1)-1;

                System.out.println("请输入你要添加的个数:");
                int c=it.Try(9);
                menu4.get(a).number=c;
                menus.add(menu4.get(a));

                }
                continue;
         case 5:
            //油炸
             System.out.println("油炸类有:");
            List<Menu> menu5=new ArrayList<Menu>(); 
            Menu[] m5={new Menu("秋刀鱼","5"),new Menu("香辣鸡胗","3"),new Menu("阿公鱿鱼须","3"),new Menu("阿公整鱿鱼","4.5"),new Menu("黄金鱼排","2"),new Menu("麻辣串烧","3"),new Menu("牙买加肉串","3"),new Menu("里脊肉","1.5"),new Menu("骨肉相连","2"),new Menu("川香鸡柳","2"),new Menu("肥羊串","3"),};
            menu5.addAll(Arrays.asList(m5));
            Collections.sort(menu5);
            int size5=menu5.size();
            for(int j=0;j<size5;j++){
                System.out.println(j+1+"\t"+menu5.get(j).name+"\t"+menu5.get(j).money);
            }

            while(true){
                 System.out.println("是否需要继续添加油炸? 1是    2不是");
                int b=it.Try(2);
                if(b==2){
                    break;
                }
               System.out.println("请输入您要选的油炸:");
            int a=it.Try(size5+1)-1;

            System.out.println("请输入你要添加的个数:");
            int c=it.Try(9);
            menu5.get(a).number=c;
            menus.add(menu5.get(a));

            }
            continue;
         case 6:
             System.out.println("您现在的账单为:");
             Collections.sort(menus);

             for(int j=0;j<menus.size();j++){
                 System.out.println(menus.get(j).name+"\t"+menus.get(j).money);

                 sum=sum+Double.parseDouble(menus.get(j).money)*menus.get(j).number;
             }
             System.out.println("总价格为:"+sum+"元");
             continue;
         case 7:
             System.out.println("您现在的账单为:");
             Collections.sort(menus);

             for(int j=0;j<menus.size();j++){
                 System.out.println(menus.get(j).name+"\t"+menus.get(j).money);

                 sum=sum+Double.parseDouble(menus.get(j).money);
             }
             System.out.println("总价格为:"+sum+"元");
             System.out.println("请输入您需要删除的序号:");
             int d=it.Try(menus.size()+1)-1;
             menus.remove(d);
             System.out.println("成功删除");
             continue;
         case 8:
             System.out.println("您现在的账单为:");
             Collections.sort(menus);

             for(int j=0;j<menus.size();j++){
                 System.out.println(menus.get(j).name+"\t"+menus.get(j).money);

                 sum=sum+Double.parseDouble(menus.get(j).money);
             }
             System.out.println("总价格为:"+sum+"元");
             p=false;
             break;
         }//switch-case语句结束

       }//主while循环结束

  }//main函数结束

}

点击查看更多内容
9人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消