Python餐厅点餐系统:Java餐厅计费系统(restaurant billing)

关于Python餐厅点餐系统的问题,在restaurant billing中经常遇到, 我是 Java 的初学者,正在尝试使用从数据库中提取的数据制作一个简单的餐厅计费系统

我是 Java 的初学者,正在尝试使用从数据库中提取的数据制作一个简单的餐厅计费系统

这是我的数据库提取

String driver = "com.mysql.cj.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/restaurant?useTimezone=true&serverTimezone=UTC";
String username ="root";
String password = "";
Scanner sc=new Scanner(System.in);
Class.forName(driver);
boolean again = true;
boolean again1 = true;
String yes;
ArrayList<String> name=new ArrayList<String>();
ArrayList<Double> price=new ArrayList<Double>();
ArrayList<String> materials=new ArrayList<String>();
ArrayList<Double> cost=new ArrayList<Double>();
HashMap<Integer,Integer> Oders=new HashMap<Integer,Integer>();
Connection conn = DriverManager.getConnection(url,username,password);
Statement myStmt = conn.createStatement();
ResultSet rs = myStmt.executeQuery("select * from food");
    while (rs.next()) {
    String  nam= rs.getString("name");
    double  pric=rs.getDouble("price");
    String  mat= rs.getString("materials");
    double  cos=rs.getDouble("cost");
    name.add(nam);
    price.add(pric);
    materials.add(mat);
    cost.add(cos);
}

这是我的计算

while(again = true){
    System.out.println("Please press y to diplay menu");
    String c=sc.next();
    char ch=c.charAt(0);
    if(ch=='y'||ch=='Y'){
        System.out.println("--------------BEMS Resturant Menu Card----------------");
        for(int i=0;i<name.size();i++){
            System.out.print(i+"."+name.get(i));
            for(int j=0;j<price.size();j++){
                System.out.println(":Rm"+price.get(i));
                break;
            }
        }
        System.out.println("");
        System.out.println("Enter your choice");
        System.out.println("--------------------------------------------------");
        while(again1 = true){
            int choice=sc.nextInt();
            System.out.println("Enter the quantity");
            int quantity=sc.nextInt();
            if(choice<=name.size()){
                if(Oders.containsKey(choice)){
                    System.out.println("Choice already present increasing the quantity for "+name.get(choice));
                    System.out.println("");
                    Oders.put(choice, Oders.get(choice)+quantity);
                }else{
            Oders.put(choice, quantity);
                }
            }else{
                System.out.println("The pressed choice does not exist in menu,enter valic choice");
                System.out.println("");
            }
            System.out.println("Wanna order something more");
            System.out.println("press Y to add more or any random key to Check Out!");
            String c1=sc.next();
            char ch1=c1.charAt(0);
            if(ch1=='y'||ch1=='Y'){
                System.out.println("Enter your choice");
            }else{
                String bill ="";
                String Total_Materials ="";
                double Total_Cost = 0;
                double Total_Bill= 0;
                double Total_Profit= 0;
                double pre =0;
                System.out.println("no more items to be ordered---->preparing final bill");
                System.out.println("--------------------BEMS Restaurant-------------------"
                        + "");
                System.out.println("Items ordered are");
                System.out.println("--------------------------------------------------");
                int count=1;
                for (int key : Oders.keySet()) {
                    System.out.println(count+"."+name.get(key)+" : "+price.get(key)+" x "+Oders.get(key));
                    Total_Materials = Total_Materials+materials.get(key);
                    Total_Cost = Total_Cost+cost.get(key);
                    Total_Bill=Total_Bill+(price.get(key))*Oders.get(key);
                    bill =bill+ name.get(key);
                    pre = Total_Bill * 0.06;
                    Total_Bill = Total_Bill + pre;
                    Total_Profit =Total_Bill - Total_Cost;
                    count++;
                }
                System.out.println("--------------------------------------------------");
                System.out.println("Total Bill : Rm."+Total_Bill);
                System.out.println("Total SST : Rm."+ pre);
                System.out.println("Materials Used: "+Total_Materials );
                System.out.println("Total Cost: "+Total_Cost );
                System.out.println("Total Profit: "+Total_Profit );
            }
        }
    } else{
        System.out.println("Exiting, that is invalid input,please try again");
        sc.close();
    }
}

我可以得到每个交易的结果,但我如何得到每一天的结果

任何答案都会很有帮助,谢谢。

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(260)
Python数据框索引:在 python数据框中创建索引查找
上一篇
文件夹大小:获取文件夹大小(file folder size)
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(80条)