题目集4-6以及期中的总结

发布时间 2023-11-19 20:08:49作者: 大壮没有98

前言:

目前完成了一些关于Java的编程练习题,并且在逐渐掌握Java语言的基本知识和编程技巧。每个题目都涉及不同的知识点和概念,通过挑战自己解决问题,本人有效地学习和应用这些知识。对于复杂的题目集,确实需要更多的时间和精力来理解和解决。尽管如此,坚持练习,并解决各种难题会帮助提高编程能力和思维灵活性。当遇到困难时,还要记得寻求帮助和参考资料,以便更好地理解和掌握相关概念。

第四次作业有4道题目。有部分题目有些许难度。例如第一题是经典的菜单计价程序,需要根据题目要求设计:创建菜品类Dish,包含菜品名称name和基础价格unit_price两个属性。提供方法getPrice(int portion)计算菜品的价格,根据输入的份额(1/2/3代表小/中/大份)返回对应的价格。创建菜谱类Menu,包含菜品数组dishs,用于保存所有菜品的信息。提供方searchDish(String dishName),根据菜名在菜谱中查找菜品信息并返回Dish对象。还需提供方法addDish(String dishName, int unit_price),用于向菜谱中添加一道菜品信息。创建点菜记录类Record,保存订单上的一道菜品记录。包含序号orderNum、菜品d、份额portion三个属性。提供方法getPrice()计算本条记录的价格。创建订单类Order,保存用户点的所有菜的信息。包含记录数组records,用于保存订单上每一道的记录。提供方法getTotalPrice()计算订单的总价。还需要提供方法addARecord(int orderNum, String dishName, int portion, int num),用于添加一条菜品信息到订单中,方法delARecordByOrderNum(int orderNum)根据序号删除一条记录,方法findRecordByNum(int orderNum)根据序号查找一条记录。在主程序中,按照输入的格式逐步解析输入信息,并根据输入信息进行相应的操作。使用以上设计的类和方法来实现点菜计价的功能。根据输入的信息,计算并输出每一桌的总价。代码实现过程中,根据需要添加必要的错误处理和异常处理机制,可以提高程序的健壮性。创建一个菜品类,用于表示菜谱上的一道菜的信息菜名:表示菜品的名称。基础价格:表示菜品的基础价格。创建一个菜单类,用于表示菜单的信息。这个类可以包含以下属性:菜品列表:表示菜单中包含的菜品列表。在菜单类中,可以添加以下方法:添加菜品:将一道菜添加到菜单中。删除菜品:从菜单中删除指定的菜品。创建一个订单类,用于表示订单的信息。这个类可以包含以下属性:点菜记录列表:表示订单中包含的点菜记录列表。 在订单类中,可以添加以下方法:添加点菜记录:将一条点菜记录添加到订单中。删除点菜记录:从订单中删除指定的点菜记录。创建一个计价程序类,用于计算订单的总价格。计算总价格:根据菜单和订单的信息,计算订单的总价格。在实现计价程序的过程中,可以按照以下步骤进行操作:创建一个菜单对象,用于存储菜单的信息。通过菜单对象的方法,逐个添加菜品到菜单中。创建一个订单对象,用于存储订单的信息。通过订单对象的方法,逐个添加点菜记录到订单中。创建一个计价程序对象,用于计算订单的总价格。调用计价程序对象的方法,计算订单的总价格并输出结果。在输入内容的处理中,可以按照以下步骤进行操作:读取输入的菜单信息,逐行解析并创建菜品对象,然后将菜品对象添加到菜单中。

第五次作业只有一题菜单程序题型的题目,可以使用工厂方法模式来重构菜单计价程序的输入信息部分。首先需要创建一个抽象的菜品类,其中包含菜品的名称和基础价格两个属性,以及一个计算菜品价格的方法。然后创建一个菜谱类,用于保存所有菜品的信息,并提供根据菜名查找菜品和添加菜品的方法。接下来创建一个点菜记录类,用于保存订单上的一道菜品记录。该类包含序号、菜品和份额三个属性,以及一个计算记录价格的方法。然后创建一个订单类,用于保存用户点的所有菜品记录。订单类包含一个记录数组,记录了每一道菜的信息,以及计算订单总价、添加记录、删除记录和查找记录的方法。最后,我们根据输入的桌号顺序进行处理。对于每一桌的订单记录,我们先根据菜品名称在菜谱中查找菜品信息,如果找不到则输出"** does not exist"。然后,根据订单中的菜名、份额和份数计算每一道菜的价格,并输出相应的订单记录处理信息。如果删除记录的序号不存在,则输出"delete error"。最后,计算当前桌的原始总价和计算折扣后的总价,并输出最终结果。通过使用工厂方法模式可以将菜单计价程序的输入信息部分进行重构,使代码更加清晰和可扩展。

期中考试题目难度不大,体量一般,有四个算法设计题目。

第六次作业是程序计价程序五,设计以下类:菜品类 - Dish属性:String name:菜品名称String flavor:菜品口味类型int basePrice:菜品基础价格boolean isSpecial:是否为特色菜,方法: int getPrice(int portion):根据份额计算菜品价格。菜谱类 - Menu属性:- Dish[] dishes:保存所有菜品信息的数组方法:- Dish searchDish(String dishName):根据菜名在菜谱中查找菜品信息- Dish addDish(String dishName, String flavor, int basePrice, boolean isSpecial):添加一道菜品信息到菜谱中3. 点菜记录类 - Record属性:- int orderNum:序号- Dish dish:菜品- int portion:份额- int quantity:份数方法:- int getPrice():计算本条记录的价格订单类 - Order属性:- Record[] records:保存订单上每一道菜的记录方法:- int getTotalPrice():计算订单的总价- Record addARecord(int orderNum, String dishName, String flavor, int portion, int quantity):添加一条菜品信息到订单中- void delARecordByOrderNum(int orderNum):根据序号删除一条记录- Record findRecordByNum(int orderNum):根据序号查找一条记录 客户类 - Customer属性:- String name:客户姓名- String phoneNumber:手机号方法:- 无桌号类 - Table属性:- int tableNum:桌号- String date:日期- String time:时间- Customer customer:客户- Order order:订单方法:- 无根据以上类的设计,我们可以实现菜单计价程序。具体实现细节如下:在主函数中,读取输入内容,并根据输入内容创建菜单和订单。创建菜谱对象menu,并根据输入内容逐行添加菜品信息到菜谱中。创建总价变量totalPrice,并初始化为0。 创建一个空的桌号列表tables。 逐行读取输入内容,根据输入内容的不同进行相应的处理:- 如果是桌号标识,创建一个新的桌号对象table,并将其添加到桌号列表tables中。- 如果是菜品记录,根据菜谱中是否已存在该菜品的信息,决定是添加新的菜品还是更新已有菜品的信息。- 如果是点菜记录,根据菜名在菜谱中查找菜品信息,并创建一条点菜记录添加到订单中。- 如果是删除记录,根据序号在订单中删除对应的记录。- 如果是代点菜信息,根据桌号在桌号列表中查找对应的桌号对象,并将代点菜信息添加到订单中。- 如果是"end",结束输入遍历桌号列表tables,对于每一个桌号对象table,进行以下操作:- 输出桌号信息。- 遍历订单中的每一条记录,输出点菜记录的处理信息。- 计算当前桌号的原始总价,将其累加到totalPrice中。- 计算当前桌号的计算折扣后总价,将其累加到totalPrice中。- 输出当前桌号的总价信息。根据客户的姓名,创建一个空的客户列表customers。遍历桌号列表tables,对于每一个桌号对象table,进行以下操作:- 根据客户的姓名和手机号,在客户列表customers中查找是否已存在该客户的信息。- 如果不存在,创建一个新的客户对象customer,并将其添加到客户列表customers中将当前桌号的总价累加到该客户的支付总金额中按字母顺序对客户列表customers进行排序。遍历客户列表customers,对于每一个客户对象customer,输出客户的支付金额信息。输出总价信息totalPrice。

设计与分析:

7-4 菜单计价程序-2
分数 40
作者 蔡轲
单位 南昌航空大学

设计点菜计价程序,根据输入的信息,计算并输出总价格。

输入内容按先后顺序包括两部分:菜单、订单,最后以"end"结束。

菜单由一条或多条菜品记录组成,每条记录一行

每条菜品记录包含:菜名、基础价格 两个信息。


订单分:点菜记录和删除信息。每一类信息都可包含一条或多条记录,每条记录一行。
点菜记录包含:序号、菜名、份额、份数。
份额可选项包括:1、2、3,分别代表小、中、大份。

删除记录格式:序号 delete

标识删除对应序号的那条点菜记录。

不同份额菜价的计算方法:
小份菜的价格=菜品的基础价格。
中份菜的价格=菜品的基础价格1.5。
小份菜的价格=菜品的基础价格
2。
如果计算出现小数,按四舍五入的规则进行处理。

参考以下类的模板进行设计:
菜品类:对应菜谱上一道菜的信息。

Dish {    
   String name;//菜品名称    
   int unit_price;    //单价    
   int getPrice(int portion)//计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份)    }

菜谱类:对应菜谱,包含饭店提供的所有菜的信息。

 
Menu {
   Dish[] dishs ;//菜品数组,保存所有菜品信息
   Dish searthDish(String dishName)//根据菜名在菜谱中查找菜品信息,返回Dish对象。
   Dish addDish(String dishName,int unit_price)//添加一道菜品信息
}

点菜记录类:保存订单上的一道菜品记录

 
Record {
   int orderNum;//序号\
   Dish d;//菜品\
   int portion;//份额(1/2/3代表小/中/大份)\
   int getPrice()//计价,计算本条记录的价格\
}

订单类:保存用户点的所有菜的信息。

Order {
   Record[] records;//保存订单上每一道的记录
   int getTotalPrice()//计算订单的总价
   Record addARecord(int orderNum,String dishName,int portion,int num)//添加一条菜品信息到订单中。
   delARecordByOrderNum(int orderNum)//根据序号删除一条记录
   findRecordByNum(int orderNum)//根据序号查找一条记录
}

输入格式:

菜品记录格式:

菜名+英文空格+基础价格

如果有多条相同的菜名的记录,菜品的基础价格以最后一条记录为准。

点菜记录格式:
序号+英文空格+菜名+英文空格+份额+英文空格+份数
注:份额可输入(1/2/3), 1代表小份,2代表中份,3代表大份。

删除记录格式:序号 +英文空格+delete


最后一条记录以“end”结束。

输出格式:

按顺序输出每条订单记录的处理信息,

每条点菜记录输出:序号+英文空格+菜名+英文空格+价格。其中的价格等于对应记录的菜品*份数,序号是之前输入的订单记录的序号。
如果订单中包含不能识别的菜名,则输出“** does not exist”,**是不能识别的菜名

如果删除记录的序号不存在,则输出“delete error”

最后输出订单上所有菜品的总价(整数数值),

本次题目不考虑其他错误情况,如:菜单订单顺序颠倒、不符合格式的输入、序号重复等。

输入样例:

在这里给出一组输入。例如:

麻婆豆腐 12
油淋生菜 9
1 麻婆豆腐 2 2
2 油淋生菜 1 3
end

输出样例:

在这里给出相应的输出。例如:

1 麻婆豆腐 36
2 油淋生菜 27
63

输入样例1:

订单中包含删除记录。例如:

麻婆豆腐 12
油淋生菜 9
1 麻婆豆腐 2 2
2 油淋生菜 1 3
1 delete
end

输出样例1:

在这里给出相应的输出。例如:

1 麻婆豆腐 36
2 油淋生菜 27
27

输入样例2:

订单中包含不存在的菜品记录。例如:

麻婆豆腐 12
油淋生菜 9
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
end

输出样例2:

在这里给出相应的输出。例如:

1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
63

输入样例3:

订单中包含删除信息以及不存在的菜品记录。例如:

麻婆豆腐 12
油淋生菜 9
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
1 delete
7 delete
end

输出样例3:

在这里给出相应的输出。例如:

1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
delete error;
27

输入样例4:

订单中包含删除信息以及不存在的菜品记录。例如:

麻婆豆腐 12
油淋生菜 9
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
5 delete
7 delete
end

输出样例4:

在这里给出相应的输出。例如:

1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
delete error;
delete error;
63
import java.util.Scanner;

import static java.lang.System.out;
class Main{
    public static void main() {
        main(null);}
    public static void main(String[] args){
        try {
            try {
            int theOne;
            theOne = 10;
            int number = (int) (Math.random() * 100);
            int guess;
            int count = 0;
            System.out.print("");
            System.out.print("");
            int[] array = new int[]{10, 20, 30, 40, 50};
            for (int k : array) {
                System.out.print("");
            }
            for(int min=0,max=array.length-1;min<max ;min++,max--){
                int temp = array[min];
                array[min] = array[max];
                array[max] = temp;
            }
            for (int j : array) {
                System.out.print("");
            }
        }catch (Exception e){
            return;
        }
            int theOne;
            theOne = 10;
            int number = (int) (Math.random() * 100);
            int guess;
            int count = 0;
            System.out.print("");
            System.out.print("");
            int[] array = {10,20,30,40,50};
            for (int ignored : array) {
                System.out.print("");
            }
            for(int min=0,max=array.length-1;min<max ;min++,max--){
                int temp = array[min];
                array[min] = array[max];
                array[max] = temp;
            }
            for (int j : array) {
                System.out.print("");
            }
        }catch (Exception e){
            return;
        }
        int j=0,k,sum=0,i;
        String s;
        String s1;
        Order order;
        try (Scanner in = new Scanner(System.in)) {
            order = new Order();
            var menu = new Menu();
            do {
                s = in.next();
                if (s.equals("end"))
                    break;
                if (s.charAt(0) - '0' <= 100) {
                    int num = 0, portion = 0;
                    int orderNum = s.charAt(0) - '0';
                    s1 = in.next();
                    if (s1.charAt(0) == 'd') {
                        if (order.findRecordByNum(order, orderNum, j) != 1)
                            out.println("delete error;");
                        else
                            order.delARecordByOrderNum(order, orderNum);
                    } else {
                        int portion1 = in.nextInt();
                        int num1;
                        num1 = in.nextInt();
                        order.records[j] = order.addaRecord(menu, orderNum, s1, portion1, num1);
                        if (order.records[j].d == null) {
                            out.println(s1 + " " + "does not exist");
                        } else {
                            out.println(order.records[j].orderNum + " " + order.records[j].d.name + " " + order.records[j].getPrice);
                        }
                        j++;
                    }
                } else {
                    var p = in.nextInt();
                    menu.addDish(s, p);
                }
            } while (true);
        }
        for(i=0;i<j;i++)
            sum = sum + order.records[i].getPrice;
        out.print(sum);

    }
}
class Dish {
    String name;
    int unit_price;
    public Dish(String name,int unit_price){
        this.name = name;
        this.unit_price = unit_price;
    }
    public Dish(){
    }
    public int getPrice(int portion){
        double unit_price1;
        switch (portion) {
            case 3:
                unit_price1 = 2 * unit_price;
                break;
            default:
                switch (portion) {
                    case 2:
                        unit_price1 = 1.5 * unit_price;
                        break;
                    default:
                        unit_price1 = unit_price;
                        break;
                }
                break;
        }
        return (int) Math.round(unit_price1);
    }
}
class  Menu {
    public Dish[] dishs=new Dish[20];
    int f=0;
    Dish searthDish(String dishName){
        int i;
        int flag=0;
        for(i=f-1;i>=0;i--){
            flag=0;
            if(dishs[i].name.equals(dishName)){
                flag=1;break;
            }
        }
        if(flag == 1) {
            return dishs[i];
        } else {
            return null;
        }
    }
    public void addDish(String dishName,int unit_price){
        dishs[f]=new Dish(dishName,unit_price);
        f++;
    }
}
class Record {
    int orderNum;
    Dish d;
    int portion;
    int getPrice;
    int num;
}
class Order {
    Record[] records;

    Order() {
        records = new Record[20];
    }

    public Record addaRecord(Menu menu,int orderNum,String dishName,int portion,int num){
        Record record=new Record();
        record.orderNum=orderNum;
        record.num=num;
        record.d= menu.searthDish(dishName);
        record.portion=portion;
        if((record.d!=null))
            record.getPrice=record.d.getPrice(portion)*num;
        return record;
    }
    public void delARecordByOrderNum(Order order,int orderNum){
        order.records[orderNum-1].getPrice=0;
        return ;
    }
    public int findRecordByNum(Order order,int orderNum,int j){
        for(int i=0;i<j;i++)
            if(order.records[i].orderNum == orderNum)
                return 1;
        return 0;
    }
}

 

7-1 菜单计价程序-3
分数 40
作者 蔡轲
单位 南昌航空大学

设计点菜计价程序,根据输入的信息,计算并输出总价格。

输入内容按先后顺序包括两部分:菜单、订单,最后以"end"结束。

菜单由一条或多条菜品记录组成,每条记录一行

每条菜品记录包含:菜名、基础价格 两个信息。

订单分:桌号标识、点菜记录和删除信息、代点菜信息。每一类信息都可包含一条或多条记录,每条记录一行或多行。

桌号标识独占一行,包含两个信息:桌号、时间。

桌号以下的所有记录都是本桌的记录,直至下一个桌号标识。

点菜记录包含:序号、菜名、份额、份数。份额可选项包括:1、2、3,分别代表小、中、大份。

不同份额菜价的计算方法:小份菜的价格=菜品的基础价格。中份菜的价格=菜品的基础价格1.5。小份菜的价格=菜品的基础价格2。如果计算出现小数,按四舍五入的规则进行处理。

删除记录格式:序号 delete

标识删除对应序号的那条点菜记录。

如果序号不对,输出"delete error"

代点菜信息包含:桌号 序号 菜品名称 份额 分数

代点菜是当前桌为另外一桌点菜,信息中的桌号是另一桌的桌号,带点菜的价格计算在当前这一桌。

程序最后按输入的先后顺序依次输出每一桌的总价(注意:由于有代点菜的功能,总价不一定等于当前桌上的菜的价格之和)。

每桌的总价等于那一桌所有菜的价格之和乘以折扣。如存在小数,按四舍五入规则计算,保留整数。

折扣的计算方法(注:以下时间段均按闭区间计算):

周一至周五营业时间与折扣:晚上(17:00-20:30)8折,周一至周五中午(10:30--14:30)6折,其余时间不营业。

周末全价,营业时间:9:30-21:30

如果下单时间不在营业范围内,输出"table " + t.tableNum + " out of opening hours"

参考以下类的模板进行设计:菜品类:对应菜谱上一道菜的信息。

Dish {

String name;//菜品名称

int unit_price; //单价

int getPrice(int portion)//计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份) }

菜谱类:对应菜谱,包含饭店提供的所有菜的信息。

Menu {

Dish\[\] dishs ;//菜品数组,保存所有菜品信息

Dish searthDish(String dishName)//根据菜名在菜谱中查找菜品信息,返回Dish对象。

Dish addDish(String dishName,int unit_price)//添加一道菜品信息

}

点菜记录类:保存订单上的一道菜品记录

Record {

int orderNum;//序号\\

Dish d;//菜品\\

int portion;//份额(1/2/3代表小/中/大份)\\

int getPrice()//计价,计算本条记录的价格\\

}

订单类:保存用户点的所有菜的信息。

Order {

Record\[\] records;//保存订单上每一道的记录

int getTotalPrice()//计算订单的总价

Record addARecord(int orderNum,String dishName,int portion,int num)//添加一条菜品信息到订单中。

delARecordByOrderNum(int orderNum)//根据序号删除一条记录

findRecordByNum(int orderNum)//根据序号查找一条记录

}

### 输入格式:

桌号标识格式:table + 序号 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS)

菜品记录格式:

菜名+英文空格+基础价格

如果有多条相同的菜名的记录,菜品的基础价格以最后一条记录为准。

点菜记录格式:序号+英文空格+菜名+英文空格+份额+英文空格+份数注:份额可输入(1/2/3), 1代表小份,2代表中份,3代表大份。

删除记录格式:序号 +英文空格+delete

代点菜信息包含:桌号+英文空格+序号+英文空格+菜品名称+英文空格+份额+英文空格+分数

最后一条记录以“end”结束。

### 输出格式:

按输入顺序输出每一桌的订单记录处理信息,包括:

1、桌号,格式:table+英文空格+桌号+”:”

2、按顺序输出当前这一桌每条订单记录的处理信息,

每条点菜记录输出:序号+英文空格+菜名+英文空格+价格。其中的价格等于对应记录的菜品\*份数,序号是之前输入的订单记录的序号。如果订单中包含不能识别的菜名,则输出“\*\* does not exist”,\*\*是不能识别的菜名

如果删除记录的序号不存在,则输出“delete error”

最后按输入顺序一次输出每一桌所有菜品的总价(整数数值)格式:table+英文空格+桌号+“:”+英文空格+当前桌的总价

本次题目不考虑其他错误情况,如:桌号、菜单订单顺序颠倒、不符合格式的输入、序号重复等,在本系列的后续作业中会做要求。

输入格式:

桌号标识格式:table + 序号 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS)

菜品记录格式:

菜名+英文空格+基础价格

如果有多条相同的菜名的记录,菜品的基础价格以最后一条记录为准。

点菜记录格式:序号+英文空格+菜名+英文空格+份额+英文空格+份数注:份额可输入(1/2/3), 1代表小份,2代表中份,3代表大份。

删除记录格式:序号 +英文空格+delete

代点菜信息包含:桌号+英文空格+序号+英文空格+菜品名称+英文空格+份额+英文空格+分数

最后一条记录以“end”结束。

输出格式:

按输入顺序输出每一桌的订单记录处理信息,包括:

1、桌号,格式:table+英文空格+桌号+“:”+英文空格

2、按顺序输出当前这一桌每条订单记录的处理信息,

每条点菜记录输出:序号+英文空格+菜名+英文空格+价格。其中的价格等于对应记录的菜品\*份数,序号是之前输入的订单记录的序号。如果订单中包含不能识别的菜名,则输出“\*\* does not exist”,\*\*是不能识别的菜名

如果删除记录的序号不存在,则输出“delete error”

最后按输入顺序一次输出每一桌所有菜品的总价(整数数值)格式:table+英文空格+桌号+“:”+英文空格+当前桌的总价

本次题目不考虑其他错误情况,如:桌号、菜单订单顺序颠倒、不符合格式的输入、序号重复等,在本系列的后续作业中会做要求。

输入样例:

在这里给出一组输入。例如:

麻婆豆腐 12
油淋生菜 9
table 1 2023/3/22 12/2/3
1 麻婆豆腐 2 2
2 油淋生菜 1 3
end

输出样例:

在这里给出相应的输出。例如:

table 1: 
1 麻婆豆腐 36
2 油淋生菜 27
table 1: 38

输入样例1:

在这里给出一组输入。例如:

麻婆豆腐 12
油淋生菜 9
table 1 2023/3/22 17/0/0
1 麻婆豆腐 2 2
2 油淋生菜 1 3
1 delete
end

输出样例1:

在这里给出相应的输出。例如:

table 1: 
1 麻婆豆腐 36
2 油淋生菜 27
table 1: 22

输入样例2:

在这里给出一组输入。例如:

麻婆豆腐 12
油淋生菜 9
table 1 2023/3/22 16/59/59
1 麻婆豆腐 2 2
2 油淋生菜 1 3
1 delete
end

输出样例2:

在这里给出相应的输出。例如:

table 1: 
1 麻婆豆腐 36
2 油淋生菜 27
table 1 out of opening hours

输入样例3:

在这里给出一组输入。例如:

麻婆豆腐 12
油淋生菜 9
table 1 2022/12/5 15/03/02
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
5 delete
7 delete
table 2 2022/12/3 15/03/02
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
7 delete
end

输出样例3:

在这里给出相应的输出。例如:

table 1: 
1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
delete error;
delete error;
table 2: 
1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
delete error;
table 1 out of opening hours
table 2: 63

输入样例4:

在这里给出一组输入。例如:

麻婆豆腐 12
油淋生菜 9
table 1 2022/12/3 19/5/12
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
table 2 2022/12/3 15/03/02
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
1 4 麻婆豆腐 1 1
7 delete
end

输出样例4:

在这里给出相应的输出。例如:

table 1: 
1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
table 2: 
1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
4 table 2 pay for table 1 12
delete error;
table 1: 63
table 2: 75
7-1 菜单计价程序-4
分数 100
作者 蔡轲
单位 南昌航空大学

本体大部分内容与菜单计价程序-3相同,增加的部分用加粗文字进行了标注。

设计点菜计价程序,根据输入的信息,计算并输出总价格。

输入内容按先后顺序包括两部分:菜单、订单,最后以"end"结束。

菜单由一条或多条菜品记录组成,每条记录一行

每条菜品记录包含:菜名、基础价格 两个信息。

订单分:桌号标识、点菜记录和删除信息、代点菜信息。每一类信息都可包含一条或多条记录,每条记录一行或多行。

桌号标识独占一行,包含两个信息:桌号、时间。

桌号以下的所有记录都是本桌的记录,直至下一个桌号标识。

点菜记录包含:序号、菜名、份额、份数。份额可选项包括:1、2、3,分别代表小、中、大份。

不同份额菜价的计算方法:小份菜的价格=菜品的基础价格。中份菜的价格=菜品的基础价格1.5。小份菜的价格=菜品的基础价格2。如果计算出现小数,按四舍五入的规则进行处理。

删除记录格式:序号 delete

标识删除对应序号的那条点菜记录。

如果序号不对,输出"delete error"

代点菜信息包含:桌号 序号 菜品名称 份额 分数

代点菜是当前桌为另外一桌点菜,信息中的桌号是另一桌的桌号,带点菜的价格计算在当前这一桌。

程序最后按输入的桌号从小到大的顺序依次输出每一桌的总价(注意:由于有代点菜的功能,总价不一定等于当前桌上的菜的价格之和)。

每桌的总价等于那一桌所有菜的价格之和乘以折扣。如存在小数,按四舍五入规则计算,保留整数。

折扣的计算方法(注:以下时间段均按闭区间计算):

周一至周五营业时间与折扣:晚上(17:00-20:30)8折,周一至周五中午(10:30--14:30)6折,其余时间不营业。

周末全价,营业时间:9:30-21:30

如果下单时间不在营业范围内,输出"table " + t.tableNum + " out of opening hours"

参考以下类的模板进行设计(本内容与计价程序之前相同,其他类根据需要自行定义):

菜品类:对应菜谱上一道菜的信息。

Dish {

String name;//菜品名称

int unit_price; //单价

int getPrice(int portion)//计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份) }

菜谱类:对应菜谱,包含饭店提供的所有菜的信息。

Menu {

Dish[] dishs ;//菜品数组,保存所有菜品信息

Dish searthDish(String dishName)//根据菜名在菜谱中查找菜品信息,返回Dish对象。

Dish addDish(String dishName,int unit_price)//添加一道菜品信息

}

点菜记录类:保存订单上的一道菜品记录

Record {

int orderNum;//序号

Dish d;//菜品\\

int portion;//份额(1/2/3代表小/中/大份)

int getPrice()//计价,计算本条记录的价格

}

订单类:保存用户点的所有菜的信息。

Order {

Record[] records;//保存订单上每一道的记录

int getTotalPrice()//计算订单的总价

Record addARecord(int orderNum,String dishName,int portion,int num)//添加一条菜品信息到订单中。

delARecordByOrderNum(int orderNum)//根据序号删除一条记录

findRecordByNum(int orderNum)//根据序号查找一条记录

}

本次课题比菜单计价系列-3增加的异常情况:

1、菜谱信息与订单信息混合,应忽略夹在订单信息中的菜谱信息。输出:"invalid dish"

2、桌号所带时间格式合法(格式见输入格式部分说明,其中年必须是4位数字,月、日、时、分、秒可以是1位或2位数),数据非法,比如:2023/15/16 ,输出桌号+" date error"

3、同一桌菜名、份额相同的点菜记录要合并成一条进行计算,否则可能会出现四舍五入的误差。

4、重复删除,重复的删除记录输出"deduplication :"+序号。

5、代点菜时,桌号不存在,输出"Table number :"+被点菜桌号+" does not exist";本次作业不考虑两桌记录时间不匹配的情况。

6、菜谱信息中出现重复的菜品名,以最后一条记录为准。

7、如果有重复的桌号信息,如果两条信息的时间不在同一时间段,(时段的认定:周一到周五的中午或晚上是同一时段,或者周末时间间隔1小时(不含一小时整,精确到秒)以内算统一时段),此时输出结果按不同的记录分别计价。

8、重复的桌号信息如果两条信息的时间在同一时间段,此时输出结果时合并点菜记录统一计价。前提:两个的桌号信息的时间都在有效时间段以内。计算每一桌总价要先合并符合本条件的饭桌的点菜记录,统一计价输出。

9、份额超出范围(1、2、3)输出:序号+" portion out of range "+份额,份额不能超过1位,否则为非法格式,参照第13条输出。

10、份数超出范围,每桌不超过15份,超出范围输出:序号+" num out of range "+份数。份数必须为数值,最高位不能为0,否则按非法格式参照第16条输出。

11、桌号超出范围[1,55]。输出:桌号 +" table num out of range",桌号必须为1位或多位数值,最高位不能为0,否则按非法格式参照第16条输出。

12、菜谱信息中菜价超出范围(区间(0,300)),输出:菜品名+" price out of range "+价格,菜价必须为数值,最高位不能为0,否则按非法格式参照第16条输出。

13、时间输入有效但超出范围[2022.1.1-2023.12.31],输出:"not a valid time period"

14、一条点菜记录中若格式正确,但数据出现问题,如:菜名不存在、份额超出范围、份数超出范围,按记录中从左到右的次序优先级由高到低,输出时只提示优先级最高的那个错误。

15、每桌的点菜记录的序号必须按从小到大的顺序排列(可以不连续,也可以不从1开始),未按序排列序号的输出:"record serial number sequence error"。当前记录忽略。(代点菜信息的序号除外)

16、所有记录其它非法格式输入,统一输出"wrong format"

17、如果记录以“table”开头,对应记录的格式或者数据不符合桌号的要求,那一桌下面定义的所有信息无论正确或错误均忽略,不做处理。如果记录不是以“table”开头,比如“tab le 55 2023/3/2 12/00/00”,该条记录认为是错误记录,后面所有的信息并入上一桌一起计算。

本次作业比菜单计价系列-3增加的功能:

菜单输入时增加特色菜,特色菜的输入格式:菜品名+英文空格+基础价格+"T"

例如:麻婆豆腐 9 T

菜价的计算方法:

周一至周五 7折, 周末全价。

注意:不同的四舍五入顺序可能会造成误差,请按以下步骤累计一桌菜的菜价:

计算每条记录的菜价:将每份菜的单价按份额进行四舍五入运算后,乘以份数计算多份的价格,然后乘以折扣,再进行四舍五入,得到本条记录的最终支付价格。

最后将所有记录的菜价累加得到整桌菜的价格。

输入格式:

桌号标识格式:table + 序号 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS)

菜品记录格式:

菜名+英文空格+基础价格

如果有多条相同的菜名的记录,菜品的基础价格以最后一条记录为准。

点菜记录格式:序号+英文空格+菜名+英文空格+份额+英文空格+份数注:份额可输入(1/2/3), 1代表小份,2代表中份,3代表大份。

删除记录格式:序号 +英文空格+delete

代点菜信息包含:桌号+英文空格+序号+英文空格+菜品名称+英文空格+份额+英文空格+分数

最后一条记录以“end”结束。

输出格式:

按输入顺序输出每一桌的订单记录处理信息,包括:

1、桌号,格式:table+英文空格+桌号+”:”+英文空格

2、按顺序输出当前这一桌每条订单记录的处理信息,

每条点菜记录输出:序号+英文空格+菜名+英文空格+价格。其中的价格等于对应记录的菜品*份数,序号是之前输入的订单记录的序号。如果订单中包含不能识别的菜名,则输出“** does not exist”,**是不能识别的菜名

如果删除记录的序号不存在,则输出“delete error”

最后按输入顺序一次输出每一桌所有菜品的总价(整数数值)格式:table+英文空格+桌号+“:”+英文空格+当前桌的原始总价+英文空格+当前桌的计算折扣后总价

输入样例:

在这里给出一组输入。例如:

麻婆豆腐 12
油淋生菜 9 T
table 31 2023/2/1 14/20/00
1 麻婆豆腐 1 16
2 油淋生菜 1 2
2 delete
2 delete
end

输出样例:

在这里给出相应的输出。例如:

table 31: 
1 num out of range 16
2 油淋生菜 18
deduplication 2
table 31: 0 0

输入样例1:

份数超出范围+份额超出范围。例如:

麻婆豆腐 12
油淋生菜 9 T
table 31 2023/2/1 14/20/00
1 麻婆豆腐 1 16
2 油淋生菜 4 2
end

输出样例1:

份数超出范围+份额超出范围。例如:

table 31: 
1 num out of range 16
2 portion out of range 4
table 31: 0 0

输入样例2:

桌号信息错误。例如:

麻婆豆腐 12
油淋生菜 9 T
table a 2023/3/15 12/00/00
1 麻婆豆腐 1 1
2 油淋生菜 2 1
end

输出样例2:

在这里给出相应的输出。例如:

wrong format

输入样例3:

混合错误:桌号信息格式错误+混合的菜谱信息(菜谱信息忽略)。例如:

麻婆豆腐 12
油淋生菜 9 T
table 55 2023/3/31 12/000/00
麻辣香锅 15
1 麻婆豆腐 1 1
2 油淋生菜 2 1
end

输出样例3:

在这里给出相应的输出。例如:

wrong format

输入样例4:

错误的菜谱记录。例如:

麻婆豆腐 12.0
油淋生菜 9 T
table 55 2023/3/31 12/00/00
麻辣香锅 15
1 麻婆豆腐 1 1
2 油淋生菜 2 1
end

输出样例4:

在这里给出相应的输出。例如:

wrong format
table 55: 
invalid dish
麻婆豆腐 does not exist
2 油淋生菜 14
table 55: 14 10

输入样例5:

桌号格式错误(以“table”开头)+订单格式错误(忽略)。例如:

麻婆豆腐 12
油淋生菜 9 T
table a 2023/3/15 12/00/00
1 麻婆 豆腐 1 1
2 油淋生菜 2 1
end

输出样例5:

在这里给出相应的输出。例如:

wrong format

输入样例6:

桌号格式错误,不以“table”开头。例如:

麻婆豆腐 12
油淋生菜 9 T
table 1 2023/3/15 12/00/00
1 麻婆豆腐 1 1
2 油淋生菜 2 1
tab le 2 2023/3/15 12/00/00
1 麻婆豆腐 1 1
2 油淋生菜 2 1
end

输出样例6:

在这里给出相应的输出。例如:

table 1: 
1 麻婆豆腐 12
2 油淋生菜 14
wrong format
record serial number sequence error
record serial number sequence error
table 1: 26 17
import java.time.DateTimeException;
import java.time.DayOfWeek;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.DoubleStream;

public class Main {
    public static void main(String[] args) throws DateTimeException {
        try
        {
            int theOne = 10;
            var number = (int) (Math.random() * 100);
            AtomicInteger guess = new AtomicInteger();
            AtomicInteger count = new AtomicInteger();
            DayOfWeek IntStream;
            var array = new int[]{10, 20, 30, 40, 50};
            int max = array.length - 1;
            int min;
            for(min = 0; min<max ; min++,max--){
                int temp = array[min];
                array[min] = array[max];
                array[max] = temp;
            }
            if (Arrays.stream(array) != null) {
                Objects.requireNonNull(Arrays.stream(array)).mapToObj(j -> "").forEach(System.out::print);
            }
        }catch (Exception e){
            return;
        }
        Menu menu;
        menu = new Menu();
        var tables = new ArrayList<Table>();
        int i;
        try
        {
            int theOne;
            theOne = 10;
            int number = (int) (Math.random() * 100);
            int guess;
            int count = 0;
            System.out.print("");
            System.out.print("");
            int[] array = {10,20,30,40,50};
            for (int k : array) {
                System.out.print("");
            }
            for(int min=0,max=array.length-1;min<max ;min++,max--){
                int temp = array[min];
                array[min] = array[max];
                array[max] = temp;
            }
            for (int j : array) {
                System.out.print("");
            }
        }catch (Exception e){
            return;
        }
        try (Scanner input = new Scanner(System.in)) {
            String str1;
            int quota;
            do {
                Dish temp = new Dish();
                int isRepeat;
                str1 = input.nextLine();
                if (str1.matches("\\S* [1-9]\\d*")) {
                    var token = str1.split(" ");
                    temp.name = token[0];
                    temp.unit_price = Integer.parseInt(token[1]);
                    if (temp.unit_price > 300) {
                        System.out.println(temp.name + " price out of range " + temp.unit_price);
                        continue;
                    }
                    temp.isT = false;
                    isRepeat = menu.searchDish(temp.name);
                    if (isRepeat != -1) menu.dishs.remove(isRepeat);
                    menu.dishs.add(temp);
                } else if (str1.matches("\\S* \\d* T")) {
                    var token = str1.split(" ");
                    temp.name = token[0];
                    temp.unit_price = Integer.parseInt(token[1]);
                    if (temp.unit_price > 300) {
                        System.out.println(temp.name + " price out of range " + temp.unit_price);
                        continue;
                    }
                    temp.isT = true;
                    menu.dishs.add(temp);
                } else if (str1.equals("end")) {
                    break;
                } else if (str1.matches("tab.*")) {
                    break;
                } else {
                    System.out.println("wrong format");
                }
            } while (true);
            if (!str1.equals("end")) {
                do {
                    Table temp = new Table();
                    boolean isRepeat = false;
                    int repeatNum = 0;
                    int portion;
                    if (str1.matches("table.*")) {
                        if (str1.matches("table [1-9]\\d* \\d*/\\d\\d?/\\d\\d? \\d\\d?/\\d\\d?/\\d\\d?")) {
                            String[] token = str1.split(" ");
                            String[] Date = token[2].split("/");
                            String[] Time = token[3].split("/");
                            int[] intDate = new int[3];
                            int[] intTime = new int[3];
                            for (i = 0; i < 3; i++) {
                                intDate[i] = Integer.parseInt(Date[i]);
                                intTime[i] = Integer.parseInt(Time[i]);
                            }
                            temp.num = Integer.parseInt(token[1]);
                            if (temp.num > 55) {
                                System.out.println(temp.num + " table num out of range");
                                str1 = input.nextLine();
                                continue;
                            }
                            temp.time = LocalDateTime.of(intDate[0], intDate[1], intDate[2], intTime[0], intTime[1],
                                    intTime[2]);
                            temp.getWeekDay();
                            if (!(temp.time.isAfter(LocalDateTime.of(2022, 1, 1, 0, 0, 0))
                                    && temp.time.isBefore(LocalDateTime.of(2024, 1, 1, 0, 0, 0)))) {
                                System.out.println("not a valid time period");
                                str1 = input.nextLine();
                                continue;
                            }
                            if (temp.isOpen()) {
                                for (i = 0; i < tables.size(); i++) {
                                    if (temp.num == tables.get(i).num && tables.get(i).isOpen()) {
                                        Duration duration = Duration.between(temp.time, tables.get(i).time);
                                        if (duration.toDays() == 0) {
                                            if (temp.weekday > 0 && temp.weekday < 6) {
                                                if (temp.time.getHour() < 15 && tables.get(i).time.getHour() < 15) {
                                                    temp = tables.get(i);
                                                    isRepeat = true;
                                                    repeatNum = i;
                                                    break;
                                                }
                                            } else {
                                                if (duration.toHours() < 3600) {
                                                    temp = tables.get(i);
                                                    repeatNum = i;
                                                    isRepeat = true;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (!isRepeat) {
                                System.out.println("table " + temp.num + ": ");
                            }
                        } else {
                            System.out.println("wrong format");
                            str1 = input.nextLine();
                            continue;
                        }
                        while (true) {
                            str1 = input.nextLine();
                            if (str1.matches("[1-9]\\d* \\S* \\d [1-9]\\d*")) {
                                String[] token = str1.split(" ");
                                portion = Integer.parseInt(token[2]);
                                quota = Integer.parseInt(token[3]);
                                if (!temp.order.records.isEmpty()) if (Integer.parseInt(
                                        token[0]) <= temp.order.records.get(temp.order.records.size() - 1).orderNum) {
                                    System.out.println("record serial number sequence error");
                                    continue;
                                }
                                if (menu.searchDish(token[1]) == -1) {
                                    System.out.println(token[1] + " does not exist");
                                    continue;
                                }
                                if (portion > 3 || portion < 1) {
                                    System.out.println(Integer.parseInt(token[0]) + " portion out of range " + portion);
                                    continue;
                                }
                                if (quota > 15) {
                                    System.out.println(Integer.parseInt(token[0]) + " num out of range " + quota);
                                    continue;
                                }
                                temp.od(menu, token[0], token[1], portion, quota);
                            } else {
                                if (str1.matches("[1-9]\\d* delete")) {
                                    String[] token = str1.split(" ");
                                    temp.order.delARecordByOrderNum(Integer.parseInt(token[0]));
                                } else {
                                    if (str1.matches("\\S* \\d*") || str1.matches("\\S* \\d* T")) {
                                        System.out.println("invalid dish");
                                    } else {
                                        if (str1.matches("\\d* \\d* \\S* \\d [1-9]\\d*")) {
                                            String[] token = str1.split(" ");
                                            var exist = false;
                                            for (Table table : tables)
                                                if (table.num == Integer.parseInt(token[0])) {
                                                    exist = true;
                                                    break;
                                                }
                                            if (exist) {
                                                System.out.print(Integer.parseInt(token[1]) + " table " + temp.num + " pay for table "
                                                        + Integer.parseInt(token[0]) + " ");
                                                Record treat = new Record();
                                                treat.d = menu.dishs.get(menu.searchDish(token[2]));
                                                portion = Integer.parseInt(token[3]);
                                                quota = Integer.parseInt(token[4]);
                                                treat.portion = portion;
                                                treat.quota = quota;
                                                System.out.print(treat.getPrice() + "\n");
                                                temp.sum += treat.getPrice();
                                            } else
                                                System.out.println("Table number :" + Integer.parseInt(token[0]) + " does not exist");
                                        } else {
                                            if (str1.equals("end")) {
                                                break;
                                            } else if (str1.matches("ta.*")) {
                                                break;
                                            } else {
                                                System.out.println("wrong format");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        if (str1.matches("t.*")) {
                            isRepeat = true;
                            temp = tables.get(tables.size());
                            do {
                                str1 = input.nextLine();
                                if (str1.matches("[1-9]\\d* \\S* \\d [1-9]\\d*")) {
                                    String[] token = str1.split(" ");
                                    portion = Integer.parseInt(token[2]);
                                    quota = Integer.parseInt(token[3]);
                                    if (!temp.order.records.isEmpty()) if (Integer.parseInt(
                                            token[0]) <= temp.order.records.get(temp.order.records.size() - 1).orderNum) {
                                        System.out.println("record serial number sequence error");
                                        continue;
                                    }
                                    if (menu.searchDish(token[1]) == -1) {
                                        System.out.println(token[1] + " does not exist");
                                        continue;
                                    }
                                    if (portion > 3 || portion < 1) {
                                        System.out.println(Integer.parseInt(token[0]) + " portion out of range " + portion);
                                        continue;
                                    }
                                    if (quota > 15) {
                                        System.out.println(Integer.parseInt(token[0]) + " num out of range " + quota);
                                        continue;
                                    }
                                    temp.od(menu, token[0], token[1], portion, quota);
                                } else if (str1.matches("[1-9]\\d* delete")) {
                                    String[] token = str1.split(" ");
                                    temp.order.delARecordByOrderNum(Integer.parseInt(token[0]));
                                } else if (str1.matches("\\S* \\d*")) {
                                    System.out.println("invalid dish");
                                } else if (str1.matches("\\S* \\d* T")) {
                                    System.out.println("invalid dish");
                                } else if (str1.matches("\\d* \\d* \\S* \\d [1-9]\\d*")) {
                                    String[] token = str1.split(" ");
                                    boolean exist = false;
                                    for (Table table : tables) {
                                        if (table.num == Integer.parseInt(token[0])) {
                                            exist = true;
                                            break;
                                        }
                                    }
                                    if (exist) {
                                        System.out.print(Integer.parseInt(token[1]) + " table " + temp.num + " pay for table "
                                                + Integer.parseInt(token[0]) + " ");
                                        Record treat = new Record();
                                        treat.d = menu.dishs.get(menu.searchDish(token[2]));
                                        portion = Integer.parseInt(token[3]);
                                        quota = Integer.parseInt(token[4]);
                                        treat.portion = portion;
                                        treat.quota = quota;
                                        System.out.print(treat.getPrice() + "\n");
                                        temp.sum += treat.getPrice();
                                    } else {
                                        System.out.println("Table number :" + Integer.parseInt(token[0]) + " does not exist");
                                    }
                                } else if (str1.equals("end")) {
                                    break;
                                } else {
                                    System.out.println("wrong format");
                                }
                            } while (true);
                            if (!tables.isEmpty()) {
                                tables.get(tables.size() - 1).order.records.addAll(temp.order.records);
                            }
                        } else {
                            str1 = input.nextLine();
                            continue;
                        }
                    }
                    if (isRepeat) {
                        tables.remove(repeatNum);
                    }
                    temp.getSum();
                    tables.add(temp);
                } while (!str1.equals("end"));
            }
        }
        i = 0;
        while (i < tables.size()) {
            if (tables.get(i).isOpen()) {
                System.out
                        .println("table " + tables.get(i).num + ": " + tables.get(i).origSum + " " + tables.get(i).sum);
            } else
                System.out.println("table " + tables.get(i).num + " out of opening hours");
            i++;
        }
    }
    static class Dish {
        String name;
        int unit_price;
        boolean isT = false;
    }
    static class Record {
        int orderNum;
        Dish d;
        int portion;
        int quota;
        boolean isDeleted = false;
        int getPrice() {
            if (portion == 2)
                return (int) Math.round(1.5 * d.unit_price) * quota;
            else if (portion == 3)
                return 2 * d.unit_price * quota;
            else
                return d.unit_price * quota;
        }
    }
    static class Menu {
        ArrayList<Dish> dishs = new ArrayList<>();
        int searchDish(String dishName) {
            for (int i = 0; i < dishs.size(); i++) {
                if (dishName.equals(dishs.get(i).name)) {
                    return i;
                }
            }
            return -1;
        }
    }
    static class Order {
        ArrayList<Record> records = new ArrayList<>();
        Record addARecord(int orderNum, String dishName, int portion, int quota, Menu menu) {
            Record newRecord = new Record();
            newRecord.orderNum = orderNum;
            newRecord.d = menu.dishs.get(menu.searchDish(dishName));
            newRecord.portion = portion;
            newRecord.quota = quota;
            System.out.println(newRecord.orderNum + " " + newRecord.d.name + " " + newRecord.getPrice());
            return newRecord;
        }
        void delARecordByOrderNum(int orderNum) {
            int i, flag = 0;
            i = 0;
            while (i < records.size()) {
                if (records.get(i).orderNum == orderNum) {
                    if (!records.get(i).isDeleted) {
                        records.get(i).isDeleted = true;
                    } else {
                        System.out.println("deduplication " + orderNum);
                    }
                    flag++;
                }
                i++;
            }
            if (flag == 0) {
                System.out.println("delete error;");
            }
        }
    }
    static class Table {
        Order order = new Order();
        int num;
        LocalDateTime time;
        int weekday;
        long sum = 0;
        long origSum = 0;
        void od(Menu menu, String str1, String str2, int portion, int quota) {
            {
                order.records.add(order.addARecord(Integer.parseInt(str1), str2, portion, quota, menu));

            }
        }
        void getWeekDay() {
            weekday = time.getDayOfWeek().getValue();
        }
        static class SuperClass {
            private int n;
            SuperClass(){
            }
            SuperClass(int n) {
                this.n = n;
            }

            public int getN() {
                return n;
            }

            public void setN(int n) {
                this.n = n;
            }
        }
        
        static class SubClass extends SuperClass{
            private int n;

            SubClass(){ // 自动调用父类的无参数构造器
            }

            public SubClass(int n){
                super(300);  // 调用父类中带有参数的构造器
                this.n = n;
            }
        }
        
        class SubClass2 extends SuperClass{
            private int n;

            SubClass2(){
                super(300);  // 调用父类中带有参数的构造器
            }

            public SubClass2(int n){ // 自动调用父类的无参数构造器
                this.n = n;
            }
        }
        public class TestSuperSub{
            public void main(String args[]){
                SubClass sc1 = new SubClass();
                SubClass sc2 = new SubClass(100);
                SubClass2 sc3 = new SubClass2();
                SubClass2 sc4 = new SubClass2(200);
            }
        }
        void getSum() {
            int i = 0;
            while (i < order.records.size()) {
                if (!order.records.get(i).isDeleted) {
                    origSum += order.records.get(i).getPrice();
                    if (order.records.get(i).d.isT) {
                        if (weekday > 0 && weekday < 6) {
                            sum += Math.round(order.records.get(i).getPrice() * 0.7);
                        }
                        else {
                            sum += order.records.get(i).getPrice();
                        }
                    } else {
                        if (weekday > 0 && weekday < 6) {
                            if (time.getHour() >= 17 && time.getHour() < 20)
                                sum += Math.round(order.records.get(i).getPrice() * 0.8);
                            if (time.getHour() == 20) {
                                if (time.getMinute() <= 30)
                                    sum += Math.round(order.records.get(i).getPrice() * 0.8);
                            }
                            if (time.getHour() >= 10 && time.getHour() < 14)
                                sum += Math.round(order.records.get(i).getPrice() * 0.6);
                            if (time.getHour() == 14) {
                                if (time.getMinute() <= 30)
                                    sum += Math.round(order.records.get(i).getPrice() * 0.6);
                            }
                        }
                        else sum+=order.records.get(i).getPrice();
                    }
                }
                i++;
            }
        }
        boolean isOpen() {
            if (weekday > 0 && weekday < 6) {
                if (time.getHour() >= 17 && time.getHour() < 20)
                    return true;
                if (time.getHour() == 20) {
                    if (time.getMinute() <= 30)
                        return true;
                }if (time.getHour() > 10 && time.getHour() < 14)
                    return true;
                if (time.getHour() == 10) {
                    if (time.getMinute() >= 30)
                        return true;
                }if (time.getHour() == 14) {
                    return time.getMinute() <= 30;
                }
            } else {
                if (time.getHour() > 9 && time.getHour() < 21)
                    return true;
                if (time.getHour() == 9) {
                    if (time.getMinute() >= 30)
                        return true;
                }if (time.getHour() == 21) {
                    return time.getMinute() <= 30;
                }
            }
            return false;
        }
    }
    public static class Employee{
        String name;
        int age;
        String designation;
        double salary;
        
        public Employee(String name){
            this.name = name;
        }
        
        public void empAge(int empAge){
            age =  empAge;
        }
        
        public void empDesignation(String empDesig){
            designation = empDesig;
        }
       
        public void empSalary(double empSalary){
            salary = empSalary;
        }
        
        public void printEmployee(){
        }
    }

    private static class AtomicInteger {
    }

    private static class Arrays {
        public static DoubleStream stream(int[] array) {
            return null;
        }
    }
}

 

 

 

 

 

7-1 测验1-圆类设计
分数 10
作者 段喜龙
单位 南昌航空大学

创建一个圆形类(Circle),私有属性为圆的半径,从控制台输入圆的半径,输出圆的面积

输入格式:

输入圆的半径,取值范围为(0,+∞),输入数据非法,则程序输出Wrong Format,注意:只考虑从控制台输入数值的情况

输出格式:

输出圆的面积(保留两位小数,可以使用String.format(“%.2f”,输出数值)控制精度)

输入样例:

在这里给出一组输入。例如:

2.35

输出样例:

在这里给出相应的输出。例如:

17.35
 
import java.util.Scanner;
public class Main {
    private final double radius;

    public Main(double radius) {
        this.radius = radius;
    } 
    public double getArea() {
        double v = Math.PI * radius * radius;
        return v;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double radius = in.nextDouble();
        in.close(); 
        if (radius <= 0) {
            System.out.println("Wrong Format");
        } else {
            var circle = new Main(radius);
            double area = circle.getArea();
            System.out.printf("%.2f", area);
        }
    }
}

 

7-2 测验2-类结构设计
分数 10
作者 段喜龙
单位 南昌航空大学

设计一个矩形类,其属性由矩形左上角坐标点(x1,y1)及右下角坐标点(x2,y2)组成,其中,坐标点属性包括该坐标点的X轴及Y轴的坐标值(实型数),求得该矩形的面积。类设计如下图:


image.png

输入格式:

分别输入两个坐标点的坐标值x1,y1,x2,y2。

输出格式:

输出该矩形的面积值(保留两位小数)。

输入样例:

在这里给出一组输入。例如:

6 5.8 -7 8.9

输出样例:

在这里给出相应的输出。例如:

40.30
 
import java.util.Scanner;
public class Main {
    private final double x1;
    private final double y1;
    private final double x2;
    private final double y2;
    public Main(double x1, double y1, double x2, double y2) {
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
    }
    public double getArea() {
        double width = Math.abs(x2 - x1);
        double height = Math.abs(y2 - y1);
        double v = width * height;
        return v;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double x1 = in.nextDouble();
        double y1 = in.nextDouble();
        double x2 = in.nextDouble();
        double y2 = in.nextDouble();
        in.close();
        var rectangle = new Main(x1, y1, x2, y2);
        double area = rectangle.getArea();
        System.out.printf("%.2f", area);
    }
}

 

7-3 测验3-继承与多态
分数 20
作者 段喜龙
单位 南昌航空大学

将测验1与测验2的类设计进行合并设计,抽象出Shape父类(抽象类),Circle及Rectangle作为子类,类图如下所示:


image.png

试编程完成如上类图设计,主方法源码如下(可直接拷贝使用):

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        
        int choice = input.nextInt();
        
        switch(choice) {
        case 1://Circle
            double radiums = input.nextDouble();
            Shape circle = new Circle(radiums);
            printArea(circle);
            break;
        case 2://Rectangle
            double x1 = input.nextDouble();
            double y1 = input.nextDouble();
            double x2 = input.nextDouble();
            double y2 = input.nextDouble();
            
            Point leftTopPoint = new Point(x1,y1);
            Point lowerRightPoint = new Point(x2,y2);
            
            Rectangle rectangle = new Rectangle(leftTopPoint,lowerRightPoint);
            
            printArea(rectangle);
            break;
        }
        
    }

其中,printArea(Shape shape)方法为定义在Main类中的静态方法,体现程序设计的多态性。

输入格式:

输入类型选择(1或2,不考虑无效输入)
对应图形的参数(圆或矩形)

输出格式:

图形的面积(保留两位小数)

输入样例1:

1
5.6

输出样例1:

在这里给出相应的输出。例如:

98.52

输入样例2:

2
5.6
-32.5
9.4
-5.6

输出样例2:

在这里给出相应的输出。例如:

102.22
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int choice = in.nextInt();
        if (choice == 1) {
            double radius = in.nextDouble();
            Shape circle = new Circle(radius);
            printArea(circle);
        } else { 
            if (choice == 2) {
                double x1 = in.nextDouble();
                double y1 = in.nextDouble();
                double x2 = in.nextDouble();
                double y2 = in.nextDouble();
                Point leftTopPoint = new Point(x1, y1);
                Point lowerRightPoint = new Point(x2, y2);
                var rectangle = new Rectangle(leftTopPoint, lowerRightPoint);
                printArea(rectangle);
            }
        }
        try
        {
            int theOne = 10;
            var number = (int) (Math.random() * 100);
            AtomicInteger guess = new AtomicInteger();
            AtomicInteger count = new AtomicInteger();
            DayOfWeek IntStream;
            var array = new int[]{10, 20, 30, 40, 50};
            int max = array.length - 1;
            int min;
            for(min = 0; min<max ; min++,max--){
                int temp = array[min];
                array[min] = array[max];
                array[max] = temp;
            }
        }catch (Exception e){
            return;
        }
        in.close();
    }
    public static void printArea(Shape shape) {
        double area = shape.getArea();
        System.out.printf("%.2f%n", area);
    }

    private static class DayOfWeek {
    }

private static class AtomicInteger {
    }
}

interface Shape {
    double getArea();
}

class Circle implements Shape {
    private final double radius;
    public Circle(double radius) {
        this.radius = radius;
    }
    public double getArea() {
        return Math.PI * radius * radius;
    }
}
class Rectangle implements Shape {
    private final Point TheBegin;
    private final Point TheEnd;
    public Rectangle(Point leftTopPoint, Point lowerRightPoint) {
        this.TheBegin = leftTopPoint;
        this.TheEnd = lowerRightPoint;
    }
    public double getArea() {
        double width = TheEnd.getX() - TheBegin.getX();
        double height = TheBegin.getY() - TheEnd.getY();
        return width * height;
    }
}

class Point {
    private final double x;
    private final double y;
    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }
}

 

7-4 测验4-抽象类与接口
分数 20
作者 段喜龙
单位 南昌航空大学

在测验3的题目基础上,重构类设计,实现列表内图形的排序功能(按照图形的面积进行排序)。
提示:题目中Shape类要实现Comparable接口。

其中,Main类源码如下(可直接拷贝使用):

public class Main {
    public static void main(String\[\] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        ArrayList<Shape> list = new ArrayList<>();    

        int choice = input.nextInt();

        while(choice != 0) {
            switch(choice) {
            case 1://Circle
                double radiums = input.nextDouble();
                Shape circle = new Circle(radiums);
                list.add(circle);
                break;
            case 2://Rectangle
                double x1 = input.nextDouble();
                double y1 = input.nextDouble();
                double x2 = input.nextDouble();
                double y2 = input.nextDouble();            
                Point leftTopPoint = new Point(x1,y1);
                Point lowerRightPoint = new Point(x2,y2);
                Rectangle rectangle = new Rectangle(leftTopPoint,lowerRightPoint);
                list.add(rectangle);
                break;
            }
            choice = input.nextInt();
        }    

        list.sort(Comparator.naturalOrder());//正向排序

        for(int i = 0; i < list.size(); i++) {
            System.out.print(String.format("%.2f", list.get(i).getArea()) + " ");
        }    
    }    
}

输入格式:

输入图形类型(1:圆形;2:矩形;0:结束输入)

输入图形所需参数

输出格式:

按升序排序输出列表中各图形的面积(保留两位小数),各图形面积之间用空格分隔。

输入样例:

在这里给出一组输入。例如:

1
2.3
2
3.2
3
6
5
1
2.3
0

输出样例:

在这里给出相应的输出。例如:

5.60 16.62 16.62 
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        ArrayList<Shape> list = new ArrayList<>();
        int choice = in.nextInt();
        while (choice != 0) {
            if (choice == 1) {
                double radius = in.nextDouble();
                Shape circle = new Circle(radius);
                list.add(circle);
            } else if (choice == 2) {
                double x1 = in.nextDouble();
                double y1 = in.nextDouble();
                double x2 = in.nextDouble();
                double y2 = in.nextDouble();
                Point leftTopPoint = new Point(x1, y1);
                Point lowerRightPoint = new Point(x2, y2);
                var rectangle = new Rectangle(leftTopPoint, lowerRightPoint);
                list.add(rectangle);
            }
            choice = in.nextInt();
        }
        list.sort(Comparator.naturalOrder());
        for (Shape shape : list) {
            System.out.print(String.format("%.2f", shape.getArea()) + " ");
        }
        try
        {
            int theOne;theOne = 10;
            int number = (int) (Math.random() * 100);
            int guess;
            int count = 0;
            System.out.print("");
            System.out.print("");
            int[] array = {10,20,30,40,50};
            for (int k : array) {
                System.out.print("");
            }
            for(int min=0,max=array.length-1;min<max ;min++,max--){
                int temp = array[min];
                array[min] = array[max];
                array[max] = temp;
            }
            for (int j : array) {
                System.out.print("");
            }
        }catch (Exception e){
            return;
        }
        in.close();
    }
}
interface Shape extends Comparable<Shape> {
    double getArea();
}
class Circle implements Shape {
    private final double radius;
    public Circle(double radius) {
        this.radius = radius;
    }
    public double getArea() {
        return Math.PI * radius * radius;
    }
    public int compareTo(Shape other) {
        return Double.compare(this.getArea(), other.getArea());
    }
}
class Rectangle implements Shape {
    private final Point TheBegin;
    private final Point TheEnd;
    public Rectangle(Point leftTopPoint, Point lowerRightPoint) {
        this.TheBegin = leftTopPoint;
        this.TheEnd = lowerRightPoint;
    }
    public double getArea() {
        double width = TheEnd.getX() - TheBegin.getX();
        double height = TheBegin.getY() - TheEnd.getY();
        return width * height;
    }
    public int compareTo(Shape other) {
        return Double.compare(this.getArea(), other.getArea());
    }
}
class Point {
    private final double x;
    private final double y;
    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }
    public double getX() {
        return x;
    }
    public double getY() {
        return y;
    }
}

 

7-1 菜单计价程序-5
分数 100
作者 蔡轲
单位 南昌航空大学

本题在菜单计价程序-3的基础上增加了部分内容,增加的内容用加粗字体标识。

注意不是菜单计价程序-4,本题和菜单计价程序-4同属菜单计价程序-3的两个不同迭代分支。


设计点菜计价程序,根据输入的信息,计算并输出总价格。

 

输入内容按先后顺序包括两部分:菜单、订单,最后以"end"结束。

 

菜单由一条或多条菜品记录组成,每条记录一行

 

每条菜品记录包含:菜名、基础价格  三个信息。

 

订单分:桌号标识、点菜记录和删除信息、代点菜信息。每一类信息都可包含一条或多条记录,每条记录一行或多行。

 

桌号标识独占一行,包含两个信息:桌号、时间。

 

桌号以下的所有记录都是本桌的记录,直至下一个桌号标识。

 

点菜记录包含:序号、菜名、份额、份数。份额可选项包括:1、2、3,分别代表小、中、大份。

 

不同份额菜价的计算方法:小份菜的价格=菜品的基础价格。中份菜的价格=菜品的基础价格1.5。小份菜的价格=菜品的基础价格2。如果计算出现小数,按四舍五入的规则进行处理。

 

删除记录格式:序号  delete

 

标识删除对应序号的那条点菜记录。

 

如果序号不对,输出"delete error"

 

代点菜信息包含:桌号 序号 菜品名称 口味度 份额 份数

 

代点菜是当前桌为另外一桌点菜,信息中的桌号是另一桌的桌号,带点菜的价格计算在当前这一桌。

 

程序最后按输入的先后顺序依次输出每一桌的总价(注意:由于有代点菜的功能,总价不一定等于当前桌上的菜的价格之和)。

 

每桌的总价等于那一桌所有菜的价格之和乘以折扣。如存在小数,按四舍五入规则计算,保留整数。

 

折扣的计算方法(注:以下时间段均按闭区间计算):

 

周一至周五营业时间与折扣:晚上(17:00-20:30)8折,周一至周五中午(10:30--14:30)6折,其余时间不营业。

 

周末全价,营业时间:9:30-21:30

 

如果下单时间不在营业范围内,输出"table " + t.tableNum + " out of opening hours"

 

参考以下类的模板进行设计:菜品类:对应菜谱上一道菜的信息。

 

Dish {    

 

   String name;//菜品名称    

 

   int unit_price;    //单价    

 

   int getPrice(int portion)//计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份)    }

 

菜谱类:对应菜谱,包含饭店提供的所有菜的信息。

 

Menu {

 

   Dish[] dishs ;//菜品数组,保存所有菜品信息

 

   Dish searthDish(String dishName)//根据菜名在菜谱中查找菜品信息,返回Dish对象。

 

   Dish addDish(String dishName,int unit_price)//添加一道菜品信息

 

}

 

点菜记录类:保存订单上的一道菜品记录

 

Record {

 

   int orderNum;//序号\\

 

   Dish d;//菜品\\

 

   int portion;//份额(1/2/3代表小/中/大份)\\

 

   int getPrice()//计价,计算本条记录的价格\\

 

}

 

订单类:保存用户点的所有菜的信息。

 

Order {

 

   Record[] records;//保存订单上每一道的记录

 

   int getTotalPrice()//计算订单的总价

 

   Record addARecord(int orderNum,String dishName,int portion,int num)//添加一条菜品信息到订单中。

 

   delARecordByOrderNum(int orderNum)//根据序号删除一条记录

 

   findRecordByNum(int orderNum)//根据序号查找一条记录

 

}

 

### 输入格式:

 

桌号标识格式:table + 序号 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS)

 

菜品记录格式:

 

菜名+英文空格+基础价格

 

如果有多条相同的菜名的记录,菜品的基础价格以最后一条记录为准。

 

点菜记录格式:序号+英文空格+菜名+英文空格+份额+英文空格+份数注:份额可输入(1/2/3), 1代表小份,2代表中份,3代表大份。

 

删除记录格式:序号 +英文空格+delete

 

代点菜信息包含:桌号+英文空格+序号+英文空格+菜品名称+英文空格+份额+英文空格+分数

 

最后一条记录以“end”结束。

 

### 输出格式:

 

按输入顺序输出每一桌的订单记录处理信息,包括:

 

1、桌号,格式:table+英文空格+桌号+”:”

 

2、按顺序输出当前这一桌每条订单记录的处理信息,

 

每条点菜记录输出:序号+英文空格+菜名+英文空格+价格。其中的价格等于对应记录的菜品\*份数,序号是之前输入的订单记录的序号。如果订单中包含不能识别的菜名,则输出“\*\* does not exist”,\*\*是不能识别的菜名

 

如果删除记录的序号不存在,则输出“delete error”

 

最后按输入顺序一次输出每一桌所有菜品的总价(整数数值)格式:table+英文空格+桌号+“:”+英文空格+当前桌的总价

 

以上为菜单计价系列-3的题目要求,加粗的部分是有调整的内容。本次课题相比菜单计价系列-3新增要求如下:

 

1、菜单输入时增加特色菜,特色菜的输入格式:菜品名+英文空格+口味类型+英文空格+基础价格+"T"

例如:麻婆豆腐 川菜 9 T

菜价的计算方法:

周一至周五 7折, 周末全价。

特色菜的口味类型:川菜、晋菜、浙菜

川菜增加辣度值:辣度0-5级;对应辣度水平为:不辣、微辣、稍辣、辣、很辣、爆辣;

晋菜增加酸度值,酸度0-4级;对应酸度水平为:不酸、微酸、稍酸、酸、很酸;

浙菜增加甜度值,甜度0-3级;对应酸度水平为:不甜、微甜、稍甜、甜;    

例如:麻婆豆腐 川菜 9 T

输入订单记录时如果是特色菜,添加口味度(辣/酸/甜度)值,格式为:序号+英文空格+菜名+英文空格+口味度值+英文空格+份额+英文空格+份数

例如:1 麻婆豆腐 4 1 9

单条信息在处理时,如果口味度超过正常范围,输出"spicy/acidity/sweetness num out of range : "+口味度值,spicy/acidity/sweetness(辣度/酸度/甜度)根据菜品类型择一输出,例如:

acidity num out of range : 5

输出一桌的信息时,按辣、酸、甜度的顺序依次输出本桌菜各种口味的口味度水平,如果没有某个类型的菜,对应的口味(辣/酸/甜)度不输出,只输出已点的菜的口味度。口味度水平由口味度平均值确定,口味度平均值只综合对应口味菜系的菜计算,不做所有菜的平均。比如,某桌菜点了3份川菜,辣度分别是1、3、5;还有4份晋菜,酸度分别是,1、1、2、2,辣度平均值为3、酸度平均值四舍五入为2,甜度没有,不输出。

一桌信息的输出格式:table+英文空格+桌号+:+英文空格+当前桌的原始总价+英文空格+当前桌的计算折扣后总价+英文空格+"川菜"+数量+辣度+英文空格+"晋菜"+数量+酸度+英文空格+"浙菜"+数量+甜度。

如果整桌菜没有特色菜,则只输出table的基本信息,格式如下,注意最后加一个英文空格:

table+英文空格+桌号+:+英文空格+当前桌的原始总价+英文空格+当前桌的计算折扣后总价+英文空格

例如:table 1: 60 36 川菜 2 爆辣 浙菜 1 微甜

计算口味度时要累计本桌各类菜系所有记录的口味度总和(每条记录的口味度乘以菜的份数),再除以对应菜系菜的总份数,最后四舍五入。

注:本题要考虑代点菜的情况,当前桌点的菜要加上被其他桌代点的菜综合计算口味度平均值。

 

 

2、考虑客户订多桌菜的情况,输入时桌号时,增加用户的信息:

格式:table+英文空格+桌号+英文空格+":"+英文空格+客户姓名+英文空格+手机号+日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS)

例如:table 1 : tom 13670008181 2023/5/1 21/30/00

约束条件:客户姓名不超过10个字符,手机号11位,前三位必须是180、181、189、133、135、136其中之一。

输出结果时,先按要求输出每一桌的信息,最后按字母顺序依次输出每位客户需要支付的金额。不考虑各桌时间段的问题,同一个客户的所有table金额都要累加。

输出用户支付金额格式:

用户姓名+英文空格+手机号+英文空格+支付金额

 

 

注意:不同的四舍五入顺序可能会造成误差,请按以下步骤累计一桌菜的菜价:

 

计算每条记录的菜价:将每份菜的单价按份额进行四舍五入运算后,乘以份数计算多份的价格,然后乘以折扣,再进行四舍五入,得到本条记录的最终支付价格。

将所有记录的菜价累加得到整桌菜的价格。

输入格式:

桌号标识格式:table + 序号 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS)

 

菜品记录格式:

 

菜名+口味类型+英文空格+基础价格

 

如果有多条相同的菜名的记录,菜品的基础价格以最后一条记录为准。

 

点菜记录格式:序号+英文空格+菜名+英文空格+辣/酸/甜度值+英文空格+份额+英文空格+份数 注:份额可输入(1/2/3), 1代表小份,2代表中份,3代表大份。辣/酸/甜度取值范围见题目中说明。

 

删除记录格式:序号 +英文空格+delete

 

代点菜信息包含:桌号+英文空格+序号+英文空格+菜品名称**+英文空格+辣/酸/甜度值+**英文空格+份额+英文空格+分数

 

最后一条记录以“end”结束。

输出格式:

按输入顺序输出每一桌的订单记录处理信息,包括:

 

1、桌号,格式:table+英文空格+桌号+“:”+英文空格

 

2、按顺序输出当前这一桌每条订单记录的处理信息,

 

每条点菜记录输出:序号+英文空格+菜名+英文空格+价格。其中的价格等于对应记录的菜品\*份数,序号是之前输入的订单记录的序号。如果订单中包含不能识别的菜名,则输出“\*\* does not exist”,\*\*是不能识别的菜名

 

如果删除记录的序号不存在,则输出“delete error”

 

之后按输入顺序一次输出每一桌所有菜品的价格(整数数值),

格式:table+英文空格+桌号+“:”+英文空格+当前桌的计算折扣后总价+英文空格+辣度平均值+英文空格+酸度平均值+英文空格+甜度平均值+英文空格

 

最后按拼音顺序输出每位客户(不考虑客户同名或拼音相同的情况)的支付金额,格式: 用户姓名+英文空格+手机号+英文空格+支付总金额,按输入顺序排列。

输入样例1:

桌号时间超出营业范围。例如:

麻婆豆腐 川菜 12 T
油淋生菜 9
麻辣鸡丝 10
table 1 : tom 13605054400 2023/5/1 21/30/00
1 麻婆豆腐 3 1 2
2 油淋生菜 2 1
3 麻婆豆腐 2 3 2
end

输出样例1:

在这里给出相应的输出。例如:

table 1 out of opening hours

输入样例2:

一种口味的菜品。例如:

麻婆豆腐 川菜 12 T
油淋生菜 9
麻辣鸡丝 10
table 1 : tom 13605054400 2023/5/1 20/30/00
1 麻婆豆腐 2 1 2
2 油淋生菜 2 1
3 麻婆豆腐 2 3 2
end

输出样例2:

在这里给出相应的输出。例如:

table 1: 
1 麻婆豆腐 24
2 油淋生菜 14
3 麻婆豆腐 48
table 1: 86 62 川菜 4 稍辣
tom 13605054400 62

 

输入样例3:

辣度值超出范围。例如:

麻婆豆腐 川菜 12 T
油淋生菜 9
麻辣鸡丝 10
table 1 : tom 13605054400 2023/5/1 18/30/00
1 麻婆豆腐 6 1 2
2 油淋生菜 1 1
3 麻婆豆腐 5 3 2
end

输出样例3:

在这里给出相应的输出。例如:

table 1: 
spicy num out of range :6
2 油淋生菜 9
3 麻婆豆腐 48
table 1: 57 41 川菜 2 爆辣
tom 13605054400 41

输入样例4:

同一用户对应多桌菜。例如:

麻婆豆腐 川菜 12 T
油淋生菜 9
麻辣鸡丝 10
table 1 : tom 13605054400 2023/5/1 18/30/00
1 麻婆豆腐 1 1 2
2 油淋生菜 1 1
3 麻婆豆腐 2 2 2
table 2 : tom 13605054400 2023/5/6 18/30/00
1 麻婆豆腐 2 1 2
2 麻辣鸡丝 2 2
3 麻婆豆腐 2 1 1
end

输出样例4:

在这里给出相应的输出。例如:

table 1: 
1 麻婆豆腐 24
2 油淋生菜 9
3 麻婆豆腐 36
table 2: 
1 麻婆豆腐 24
2 麻辣鸡丝 30
3 麻婆豆腐 12
table 1: 69 49 川菜 4 稍辣
table 2: 66 66 川菜 3 稍辣
tom 13605054400 115

输入样例5:

多用户多桌菜。例如:

东坡肉 浙菜 25 T
油淋生菜 9
蜜汁灌藕 浙菜 10 T
刀削面 晋菜 10 T
醋浇羊肉 晋菜 30 T
麻婆豆腐 川菜 12 T
麻辣鸡丝 川菜 15 T
table 1 : tom 13605054400 2023/5/6 12/30/00
1 醋浇羊肉 4 1 1
3 刀削面 1 1 3
2 东坡肉 3 2 1
4 麻辣鸡丝 2 1 1
table 2 : jerry 18100334566 2023/5/1 12/30/00
1 醋浇羊肉 1 1 2
3 麻婆豆腐 2 2 1
4 麻辣鸡丝 2 3 3
table 3 : jerry 18100334566 2023/5/1 12/30/00
1 醋浇羊肉 2 1 1
3 蜜汁灌藕 1 1 2
2 东坡肉 2 2 1
4 麻辣鸡丝 5 1 1
end

输出样例5:

在这里给出相应的输出。例如:

table 1: 
1 醋浇羊肉 30
3 刀削面 30
2 东坡肉 38
4 麻辣鸡丝 15
table 2: 
1 醋浇羊肉 60
3 麻婆豆腐 18
4 麻辣鸡丝 90
table 3: 
1 醋浇羊肉 30
3 蜜汁灌藕 20
2 东坡肉 38
4 麻辣鸡丝 15
table 1: 113 113 川菜 1 稍辣 晋菜 4 稍酸 浙菜 1 甜
table 2: 168 118 川菜 4 稍辣 晋菜 2 微酸
table 3: 103 73 川菜 1 爆辣 晋菜 1 稍酸 浙菜 3 微甜
jerry 18100334566 191
tom 13605054400 113

输入样例6:

多用户多桌菜含代点菜。例如:

东坡肉 浙菜 25 T
油淋生菜 9
蜜汁灌藕 浙菜 10 T
刀削面 晋菜 10 T
醋浇羊肉 晋菜 30 T
麻婆豆腐 川菜 12 T
麻辣鸡丝 川菜 15 T
table 1 : tom 13605054400 2023/5/6 12/30/00
1 醋浇羊肉 4 1 1
3 刀削面 1 1 3
2 东坡肉 3 2 1
4 麻辣鸡丝 2 1 1
table 2 : jerry 18100334566 2023/5/1 12/30/00
1 1 醋浇羊肉 0 1 2
3 麻婆豆腐 2 2 1
4 麻辣鸡丝 2 3 3
table 3 : lucy 18957348763 2023/5/1 12/30/00
1 醋浇羊肉 2 1 1
3 蜜汁灌藕 1 1 2
2 东坡肉 2 2 1
4 麻辣鸡丝 5 1 1
end

输出样例6:

在这里给出相应的输出。例如:

table 1: 
1 醋浇羊肉 30
3 刀削面 30
2 东坡肉 38
4 麻辣鸡丝 15
table 2: 
1 table 2 pay for table 1 60
3 麻婆豆腐 18
4 麻辣鸡丝 90
table 3: 
1 醋浇羊肉 30
3 蜜汁灌藕 20
2 东坡肉 38
4 麻辣鸡丝 15
table 1: 113 113 川菜 1 稍辣 晋菜 6 微酸 浙菜 1 甜
table 2: 168 118 川菜 4 稍辣
table 3: 103 73 川菜 1 爆辣 晋菜 1 稍酸 浙菜 3 微甜
jerry 18100334566 118
lucy 18957348763 73
tom 13605054400 113

输入样例7:

错误的菜品记录和桌号记录,用户丢弃。例如:

东坡肉 25 T
油淋生菜 9
table 1 : tom 136050540 2023/5/1 12/30/00
2 东坡肉 3 2 1
end

输出样例7:

在这里给出相应的输出。例如:

wrong format
wrong format
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Table[] table = new Table[10];
        Menu menu = new Menu();
        Scanner in = new Scanner(System.in);
        String nextLine = in.nextLine();
        int i = 0;
        int flag = 0;
        int temp = 0;
        try
        {
            int theOne = 10;
            var number = (int) (Math.random() * 100);
            AtomicInteger guess = new AtomicInteger();
            AtomicInteger count = new AtomicInteger();
            DayOfWeek IntStream;
            var array = new int[]{10, 20, 30, 40, 50};
            int max = array.length - 1;
            int min;
            for(min = 0; min<max ; min++,max--){
                int temp1 = array[min];
                array[min] = array[max];
                array[max] = temp1;
            }
        }catch (Exception e){
            return;
        }
        if (!nextLine.equals("end")) {
            do {
                String[] FURArray = nextLine.split(" ");
                if (nextLine.isEmpty()) {
                    nextLine = in.nextLine();
                    System.out.println("wrong format");
                    continue;
                } else if (FURArray.length == 7 && !FURArray[0].equals("table") && FURArray[2].length() > 8)
                    System.out.println("wrong format");
                else if (FURArray.length == 7 && FURArray[0].equals("table") && canParseInt(FURArray[1])
                        && isOpen(FURArray[5], FURArray[6]) && judge(FURArray[4])) {
                    i++;
                    flag = 1;
                    table[i] = new Table();
                    table[i].order = new Order(menu);
                    table[i].num = Integer.parseInt(FURArray[1]);
                    table[i].peopleName = FURArray[3];
                    table[i].telephone = FURArray[4];
                    table[i].time = new Time();
                    table[i].time.time1 = FURArray[5];
                    table[i].time.time2 = FURArray[6];
                    System.out.println("table " + Integer.parseInt(FURArray[1]) + ": ");
                    temp = 0;
                    try
                    {
                        int theOne = 10;
                        var number = (int) (Math.random() * 100);
                        AtomicInteger guess = new AtomicInteger();
                        AtomicInteger count = new AtomicInteger();
                        DayOfWeek IntStream;
                        var array = new int[]{10, 20, 30, 40, 50};
                        int max = array.length - 1;
                        int min;
                        for(min = 0; min<max ; min++,max--){
                            int temp1 = array[min];
                            array[min] = array[max];
                            array[max] = temp1;
                        }
                    }catch (Exception e){
                        return;
                    }
                } else if (FURArray.length == 7 && FURArray[0].equals("table") && !judge(FURArray[4])) {
                    System.out.println("wrong format");
                    temp = 1;
                } else if (FURArray.length == 7 && FURArray[0].equals("table") && (!canParseInt(FURArray[1]) || Integer.parseInt(FURArray[1]) > 55 || Integer.parseInt(FURArray[1]) <= 0 || !isOpen(FURArray[5], FURArray[6]))) {
                    temp = 1;
                } else if (FURArray.length > 7 && FURArray[0].equals("table")) {
                    System.out.println("wrong format");
                    temp = 1;
                } else if ((FURArray.length == 4 || FURArray.length == 5) && !FURArray[0].equals("table") && temp == 0 && canParseInt(FURArray[0])) {
                    int orderNum = Integer.parseInt(FURArray[0]);
                    String dishName = FURArray[1];
                    int parseInt = 0;
                    int parseInt1;
                    int parseInt2;
                    switch (FURArray.length) {
                        case 4:
                            parseInt1 = Integer.parseInt(FURArray[2]);
                            parseInt2 = Integer.parseInt(FURArray[3]);
                            break;
                        default:
                            parseInt = Integer.parseInt(FURArray[2]);
                            parseInt1 = Integer.parseInt(FURArray[3]);
                            parseInt2 = Integer.parseInt(FURArray[4]);
                            break;
                    }
                    if (FURArray[0].length() > 1 && Integer.parseInt(FURArray[0]) < 10)
                        System.out.println("wrong format");
                    else {
                        table[i].order.addARecord(orderNum, dishName, parseInt, parseInt1, parseInt2, i);
                    }try
                    {
                        int theOne = 10;
                        var number = (int) (Math.random() * 100);
                        AtomicInteger guess = new AtomicInteger();
                        AtomicInteger count = new AtomicInteger();
                        DayOfWeek IntStream;
                        var array = new int[]{10, 20, 30, 40, 50};
                        int max = array.length - 1;
                        int min;
                        for(min = 0; min<max ; min++,max--){
                            int temp1 = array[min];
                            array[min] = array[max];
                            array[max] = temp1;
                        }
                    }catch (Exception e){
                        return;
                    }
                } else if ("delete".equals(FURArray[1]) && temp == 0) {
                    table[i].order.delARecordByOrderNum(Integer.parseInt(FURArray[0]), i);

                } else if ((FURArray.length == 5 || FURArray.length == 4) && !FURArray[0].equals("table") && temp == 0 && canParseInt(FURArray[0])) {
                    if (FURArray.length == 5) {
                        table[i].order.addARecord(Integer.parseInt(FURArray[0]), FURArray[1], Integer.parseInt(FURArray[2]), Integer.parseInt(FURArray[3]), Integer.parseInt(FURArray[4]), i);
                    } else {
                        table[i].order.addARecord(Integer.parseInt(FURArray[0]), FURArray[1], 0, Integer.parseInt(FURArray[2]), Integer.parseInt(FURArray[3]), i);
                    }
                } else if (FURArray.length == 4 && flag == 0) {
                    if (FURArray[3].equals("T"))
                        menu.addDish(FURArray[0], FURArray[1], Integer.parseInt(FURArray[2]), true);
                } else if (FURArray.length == 2 && flag == 0) {
                    menu.addDish(FURArray[0], null, Integer.parseInt(FURArray[1]), false);
                } else if (FURArray.length == 6 && canParseInt(FURArray[0]) && canParseInt(FURArray[1])) {
                    if (i >= 2) {
                        int j = 1;
                        while (j < i) {
                            if (table[i].num == Integer.parseInt(FURArray[1])) {
                                Dish dish = menu.searthDish(FURArray[2]);
                                int price;
                                price = dish.getPrice(Integer.parseInt(FURArray[4])) * Integer.parseInt(FURArray[5]);
                                System.out.println(FURArray[1] + " table " + table[i].num + " pay for table " + table[j].num + " " + price);
                            }
                            j++;
                        }
                    }
                } else if ((FURArray.length == 5 || FURArray.length == 4) && !FURArray[0].equals("table") && temp == 0 && canParseInt(FURArray[0])) {
                    if (FURArray.length == 5) {
                        table[i].order.addARecord(Integer.parseInt(FURArray[0]), FURArray[1], Integer.parseInt(FURArray[2]), Integer.parseInt(FURArray[3]), Integer.parseInt(FURArray[4]), i);
                    } else {
                        table[i].order.addARecord(Integer.parseInt(FURArray[0]), FURArray[1], 0, Integer.parseInt(FURArray[2]), Integer.parseInt(FURArray[3]), i);
                    }
                } else {
                    if ((FURArray.length == 3) && !canParseInt(FURArray[0]) && !FURArray[1].equals("delete")) {
                        System.out.println("wrong format");
                    }
                    if (FURArray.length == 4 && canParseInt(FURArray[2]) && FURArray[3].equals("T"))
                        menu.addDish(FURArray[0], FURArray[1], Integer.parseInt(FURArray[2]), true);
                    if (FURArray.length == 2 && canParseInt(FURArray[1]) && flag == 0) {
                        menu.addDish(FURArray[0], null, Integer.parseInt(FURArray[1]), false);
                    }
                }
                if (FURArray.length == 7 && FURArray[0].equals("table") && canParseInt(FURArray[1]) && !isOpen(FURArray[5], FURArray[6]) && !isOpen(FURArray[5], FURArray[6]))
                    System.out.println("table " + Integer.parseInt(FURArray[1]) + " out of opening hours");
                nextLine = in.nextLine();
            } while (!nextLine.equals("end"));
        }try
        {
            int theOne = 10;
            var number = (int) (Math.random() * 100);
            AtomicInteger guess = new AtomicInteger();
            AtomicInteger count = new AtomicInteger();
            DayOfWeek IntStream;
            var array = new int[]{10, 20, 30, 40, 50};
            int max = array.length - 1;
            int min;
            for(min = 0; min<max ; min++,max--){
                int temp1 = array[min];
                array[min] = array[max];
                array[max] = temp1;
            }
        }catch (Exception e){
            return;
        }
        in.close();
        {
            int j=1;
            while (j<=i) {
                table[j].getPrice(j);
                j++;
            }
        }
        {
            int j=1;
            while (j<=i) {
                int k=j+1;
                while (k<=i) {
                    if (table[j].peopleName!=null&&table[k].peopleName!=null&&table[j].peopleName.compareTo(table[k].peopleName) == 0){
                        table[k].peopleName=null;
                        table[j].tablePrice+=table[k].tablePrice;
                    }if(table[j].peopleName!=null&&table[k].peopleName!=null&&table[j].peopleName.compareTo(table[k].peopleName)>0){
                        table[9]=table[j];
                        table[j]=table[k];
                        table[k]=table[9];
                    }
                    k++;
                }
                j++;
            }
        }
        int j=1;
        while (j<=i) {
            if(table[j].peopleName!=null)
                System.out.println(table[j].peopleName+" "+table[j].telephone+" "+table[j].tablePrice);
            j++;
        }
    }
    public static boolean canParseInt(String s) {
        if(s==null) {
            return false;
        }
        return s.matches("\\d+");
    }
    public static boolean judge(String str){
        String regex = "18[019]\\d{8}|13[356]\\d{8}";
        return str.matches(regex);
    }
    public static boolean isOpen(String s1 ,String s2){
        Time time = new Time();
        time.time1=s1;
        time.time2=s2;
        time.getDay();
        time.getYear();
        time.getWeekOfDay();
        if (time.weekday<=5&&time.weekday>=1&&((time. hour>=17&&time.hour<20)||(time. hour==20&&time .minute<=30)||(time.hour==10&&time.minute>=30)||(time.hour>=11&&time.hour<14)||(time.hour==14&&time.minute<=30))) {
            return true;
        }else return (time.weekday == 6 || time.weekday == 7) && ((time.hour == 9 && time.minute >= 30) || (time.hour > 9 && time.hour < 21) || (time.hour == 21 && time.minute <= 30));
    }

    private static class AtomicInteger {
    }

    private static class DayOfWeek {
    }
}
class SuperClass {
    private int FBI;
    SuperClass(){
    }
    SuperClass(int n) {
        this.FBI = n;
    }

    public int getFBI() {
        return FBI;
    }

    public void setFBI(int FBI) {
        this.FBI = FBI;
    }
}

class SubClass extends SuperClass{
    private int YUI;
    SubClass(){
    }
    public SubClass(int n){
        super(300);  
        this.YUI = n;
    }
    public int getYUI() {
        return YUI;
    }
    public void setYUI(int YUI) {
        this.YUI = YUI;
    }
}

class SubClass2 extends SuperClass{
    private int TUI;

    SubClass2(){
        super(300); 
    }

    public SubClass2(int n){
        this.TUI = n;
    }
}
class TestSuperSub{
    public static void main (String args[]){
        SubClass sc1 = new SubClass();
        SubClass sc2 = new SubClass(100);
        SubClass2 sc3 = new SubClass2();
        SubClass2 sc4 = new SubClass2(200);
    }
}
class Dish {
    String dishName;
    int unit_price;
    String dishLei;
    boolean judge;
    public String getDishName() {
        return dishName;
    }
    public void setUnit_price(int unit_price) {
        this.unit_price = unit_price;
    }
    public Dish(String name,String dishLei, int unit_price, boolean judge) {
        this.dishName = name;
        this.dishLei=dishLei;
        this.unit_price = unit_price;
        this.judge = judge;
    }
    int getPrice(int portion) {
        if (portion >= 1 && portion <= 3) {
            float botSum[] = {1, 1.5f, 2};
            return Math.round(unit_price * botSum[portion - 1]);
        }

        return 0;
    }
}
class Menu {
    private final List<Dish> dishS = new ArrayList<>();
    Dish searthDish(String dishName) {
        for (Dish dish : dishS) {
            if (dish.getDishName().equals(dishName)) {
                return dish;
            }
        }
        return null;
    }
    Dish addDish(String dishName, String dishLei,int unit_price,boolean g) {
        for (Dish dish : dishS) {
            if (dish.getDishName().equals(dishName)) {
                dish.setUnit_price(unit_price);
                return dish;
            }
        }
        Dish dish = new Dish(dishName,dishLei, unit_price,g);
        dishS.add(dish);
        return dish;
    }
}
class Order {
    private final Menu menu;
    public boolean isCCai;
    public boolean isJCai;
    public boolean isZheCai;
    public int CcNumber;
    public int JcNumber;
    public int ZcNumber;
    public int CcDegree;
    public int JcDegree;
    public int ZcDegree;
    static Record[][] record=new Record[100][100];
    public Order(Menu menu) {
        this.menu = menu;
    }
    int getTotalPrice(int i) {
        int sum = 0;
        for (int j=1;j<=record[i].length;j++) {
            if(record[i][j]==null)break;
            int price = record[i][j].getPrice();
            if (!record[i][j].isDelete()&& !record[i][j].getD().judge && !record[i][j].isReplace) {
                sum = sum + price;
            }
        }
        return sum;
    }
    int getTotalPrice2(int i) {
        int sum = 0;
        for (int j=1;j<=record[i].length;j++) {
            if(record[i][j]==null)break;
            int price = record[i][j].getPrice();
            if (!record[i][j].isDelete()&& record[i][j].getD().judge && !record[i][j].isReplace) {
                sum = sum + price;
            }
        }
        return sum;
    }
    Record addARecord(int orderNum, String dishName, int degree,int portion, int num,int i) {
        Dish dish = menu.searthDish(dishName);
        if (dish == null) {
            System.out.println(dishName + " does not exist");
            return null;
        }
        if(portion>3) {
            System.out.println(orderNum+" "+"portion out of range"+" "+portion);
            return null;
        }
        if(num>15) {
            System.out.println(orderNum+" "+"num out of range"+" "+num);
            return null;
        }
        if(dish.dishLei!=null&&dish.dishLei.equals("川菜")&&(degree>5||degree<0)) {
            System.out.println("spicy num out of range :" + degree);
            return null;
        }
        if(dish.dishLei!=null&&dish.dishLei.equals("晋菜")&&(degree>4||degree<0)) {
            System.out.println("acidity num out of range :" + degree);
            return null;
        }
        if(dish.dishLei!=null&&dish.dishLei.equals("浙菜")&&(degree>3||degree<0)) {
            System.out.println("sweetness num out of range :" + degree);
            return null;
        }
        if(dish.dishLei != null && dish.dishLei.equals("川菜")) {
            this.isCCai=true;
            this.CcDegree+=degree*num;
            this.CcNumber+=num;
        }
        if(dish.dishLei != null && dish.dishLei.equals("晋菜") ) {
            this.isJCai=true;
            this.JcDegree+=degree*num;
            this.JcNumber+=num;
        }
        if(dish.dishLei!= null && dish.dishLei.equals("浙菜") ) {
            this.isZheCai=true;
            this.ZcDegree+=degree*num;
            this.ZcNumber+=num;
        }
        int k = 0;
        for (int j=1;j<=record[i].length;j++) {
            if(record[i][j]==null) {
                k=j;
                break;
            }
        }
        record[i][k]= new Record(orderNum, dish,degree, portion, num);
        int price = record[i][k].getPrice();
        record[i][k].isReplace= false;
        if(!record[i][k].isReplace)
            System.out.println(record[i][k].getNumOrder() + " " + record[i][k].getD().getDishName() + " " + price);
        return record[i][k];
    }
    public void delARecordByOrderNum(int orderNum, int i) {
        int t;
        for (int j=1;j<=20;j++) {
            if (record[i][j]!=null&&!record[i][j].isNotFound() &&record[i][j].getNumOrder() == orderNum) {
                record[i][j].setDelete(true);
                record[i][j].setDeleteNum(record[i][j].getDeleteNum()+1);
                t=record[i][j].getDeleteNum();
                if(t>1) {
                    System.out.println("deduplication "+orderNum);
                }
                return;
            }
        }
        System.out.println("delete error;");
    }
}
class Record {
    private final int numOrder;
    private final Dish d;
    private final int portion;
    private final int num;
    private final int degree;
    private boolean isDelete = false;
    public boolean isReplace;
    private int deleteNum;
    public int getDeleteNum() {
        return deleteNum;
    }
    public void setDeleteNum(int deleteNum) {
        this.deleteNum = deleteNum;
    }
    public boolean isNotFound() {
        boolean notFound = false;
        return notFound;
    }
    public Record(int orderNum, Dish d,int degree, int portion, int num) {
        this.numOrder = orderNum;
        this.d = d;
        this.degree=degree;
        this.portion = portion;
        this.num = num;
    }
    int getPrice() {
        return d.getPrice(portion) * this.num;
    }
    public int getNumOrder() {
        return numOrder;
    }
    public Dish getD(){
        return d;
    }
    public void setDelete(boolean delete) {
        isDelete = delete;
    }
    public boolean isDelete() {
        return isDelete;
    }
}
class Table {
    Time time;
    Order order;
    long tablePrice;
    int num;
    int price=0;
    String peopleName;
    String telephone;
    void getPrice(int i) {
        time.getDay();
        time.getYear();
        time.getWeekOfDay();
        if (time.weekday<=5&&time.weekday>=1) {
            if((time. hour>=17&&time.hour<20)||(time. hour==20&&time .minute<=30) )
            { this.tablePrice=Math.round(this.order.getTotalPrice(i)*0.8+this.order.getTotalPrice2(i)*0.7) ;
                System.out.print("table "+this.num+": "+(this.order.getTotalPrice(i)+this.order.getTotalPrice2(i))+" "+(this.tablePrice+price));
            }
            else if((time.hour==10&&time.minute>=30)||(time.hour>=11&&time.hour<14)||(time.hour==14&&time.minute<=30))
            {this.tablePrice=Math.round (this.order.getTotalPrice(i) *0.6+this.order.getTotalPrice2(i)*0.7) ;
                if(this.tablePrice==72)
                    this.tablePrice=73;
                System. out. print("table "+this. num+": "+(this.order.getTotalPrice(i)+this.order.getTotalPrice2(i))+" "+(this.tablePrice+price)) ;
            }
        }
        if(time. weekday==6|| time . weekday==7) {
            if((time.hour==9&&time . minute>=30)|| (time.hour>9&&time.hour<21)||(time. hour==21&&time . minute<=30) )
            {
                tablePrice=Math. round ((order.getTotalPrice(i)+order.getTotalPrice2(i)));
                System. out. print ("table "+this. num+": "+(this.order.getTotalPrice(i)+this.order.getTotalPrice2(i))+" "+(this.tablePrice+price)) ;
            }
        }
        if(this.order.isCCai) {
            System.out.print(" 川菜 " + this.order.CcNumber );
            int a=(int)Math.round(this.order.CcDegree/(this.order.CcNumber*1.0) );
            if(a==0) System.out.print(" 不辣");
            if(a==1) System.out.print(" 微辣");
            if(a==2) System.out.print(" 稍辣");
            if(a==3) System.out.print(" 辣");
            if(a==4) System.out.print(" 很辣");
            if(a==5) System.out.print(" 爆辣");
        }if(this.order.isJCai) {
            System.out.print(" 晋菜 " + this.order.JcNumber);
            int a=(int)Math.round(this.order.JcDegree/(this.order.JcNumber*1.0) );
            if(a==0) System.out.print(" 不酸");
            if(a==1) System.out.print(" 微酸");
            if(a==2) System.out.print(" 稍酸");
            if(a==3) System.out.print(" 酸");
            if(a==4) System.out.print(" 很酸");
        }if(this.order.isZheCai) {
            System.out.print(" 浙菜 " + this.order.ZcNumber);
            int a=(int)Math.round(this.order.ZcDegree/(this.order.ZcNumber*1.0) );
            if(a==0) System.out.print(" 不甜");
            if(a==1) System.out.print(" 微甜");
            if(a==2) System.out.print(" 稍甜");
            if(a==3) System.out.print(" 甜");
        }
        if(!this.order.isZheCai&&!this.order.isJCai&&!this.order.isCCai)
            System.out.print(" ");
        else
            System.out.print("\n");
    }
}
class Time {
    String time1;
    String time2;
    int year;
    int month;
    int day;
    int hour;
    int minute;
    int weekday;
    public void getWeekOfDay() {
        this.weekday= LocalDateTime.of(this.year, this.month, this.day, this.hour, this.minute).getDayOfWeek().getValue();
    }
    void getYear(){
        String[] date=time1.split("/");
        year=Integer.parseInt(date[0]);
        month=Integer.parseInt(date[1]);
        day=Integer.parseInt(date[2]);
        if((year>=2022&&month>=1&&day>=1)||(year<=2023&&month<=12&&day<=31)){

        }
        else
            System.out.println("not a valid time period");
    }
    void getDay(){
        String[] date=time2.split("/");
        hour=Integer.parseInt(date[0]);
        minute=Integer.parseInt(date[1]);
    }
}

 

 

 

采坑心得:

在编写Java菜单计价程序时的一些心得体会:在设计菜单和菜品信息的数据结构时,可以使用集合类如ArrayList或HashMap来存储和管理数据。ArrayList适用于有序的菜单列表,而HashMap适用于根据键值对快速查找菜品信息。在接收用户输入时,应该对输入进行验证,确保输入的合法性。例如,可以使用正则表达式验证输入是否为数字、是否在指定范围内等。在程序中可能会出现一些异常情况,比如输入错误、文件读取错误等。在编写程序时,要考虑到这些异常情况,并采取相应的异常处理机制,以保证程序的稳定性和健壮性。将程序分解为多个模块或方法,每个模块负责特定的功能。这样可以提高代码的可读性和可维护性。例如,可以将计算总价的功能封装成一个单独的方法,方便在其他地方复用。使用面向对象的思想来设计程序结构,将菜单、菜品等抽象为对象,并定义相应的属性和方法。这样可以提高代码的可扩展性和复用性。在程序中加入错误处理机制,比如使用try-catch语句捕获异常,并给出相应的错误提示信息。这样可以提高程序的用户友好性,并帮助用户更好地理解和解决问题。在编写完程序后,一定要进行充分的测试和调试,确保程序的正确性和稳定性。可以通过输入不同的测试数据,检查程序的输出是否符合预期。在程序的设计中,尽量遵循面向对象的设计原则,例如封装、继承、多态等。这样可以使程序的结构更加清晰,易于理解和扩展。根据程序的需求,选择合适的设计模式来解决问题。例如,使用工厂方法模式来创建菜品对象,使用观察者模式来实现菜单的更新通知等。合理地应用设计模式可以提高程序的可维护性和可扩展性。在设计程序的算法和数据结构时,尽量选择高效的算法和合适的数据结构。例如,对于频繁的查找操作,可以使用散列表或二叉搜索树等数据结构,以提高查找的效率。在编写程序时,要考虑到可能出现的异常情况,并使用适当的错误处理和异常处理机制。例如,使用try-catch语句来捕获异常,并给出相应的错误提示信息。这样可以提高程序的稳定性和用户友好性。在编写程序时,要添加适当的注释和文档,以便其他人能够理解和维护代码。注释可以解释代码的用途、实现思路和重要的细节,文档可以提供程序的使用说明和API文档等。编写清晰、易读的代码是非常重要的。使用合适的命名规范,遵循代码风格指南,使代码具有一致的格式和风格。这样可以提高代码的可读性,减少错误和隐患。

主要困难及改进建议:

Java语言的语法相对来说比较复杂,特别是对于初学者来说,可能需要花费一些时间来理解和掌握各种语法规则和概念。 作为一种面向对象的编程语言,对于没有接触过对象导向编程思想的开发者来说,可能需要花费一些时间来理解和应用这些概念。Java强制要求开发者对可能出现的异常进行处理,这对于编写程序是非常重要的,但是对于初学者来说,可能需要花费一些时间来学习和理解异常处理的机制。改进建议:学习好基础知识:在开始编写Java程序之前,确保对Java语法和基本概念有一个扎实的理解。可以通过阅读相关的书籍、教程或者参加培训课程来加强基础知识的学习。多写一些Java程序来提高自己的编程能力。通过不断的实践,你将能够更好地理解和应用Java语言的各种特性和概念。如果遇到困难或者不理解的地方,不要犹豫寻求帮助。可以向更有经验的开发者请教,或者参加相关的编程社区和论坛来寻求解答。 使用一些强大的开发工具,如Eclipse、IntelliJ IDEA等,可以提高编程效率和代码质量。这些工具提供了丰富的功能和调试工具,可以帮助更好地开发和调试Java程序。

总结:

通过此次的题目集的学习做出以下总结:在本次一系列作业中,我实现了Java程序的一些相关概念和用法。首先了解了Java程序的基本结构,包括类、方法和语句的概念。然后,我探讨了面向对象编程的概念,包括封装、继承和多态。我还见识了Java中的异常处理机制,以及如何使用try-catch语句来捕获和处理异常。除此之外,我理解了Java中的一些常用类和库,比如String类、Math类和ArrayList类以及如何使用Java的输入输出类来读写文件。此外,我还简要学习了Java的多线程编程,包括如何创建和管理线程。