首页 > 其他分享 >BLOG-2

BLOG-2

时间:2023-06-30 20:55:04浏览次数:36  
标签:int 31 System month BLOG year out

  • 前言   
    •  知识点:期中考试主要考察了,继承,抽象类,多态,Comparable接口
    • 题量 :还可以
    • 难度:很简单
  • 设计与分析
    • 菜单4
    1. 类图

                                                                          

                                    

      2.源代码

      

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 类名称 对象数组名[] = new 类名称[长度];
        Dish d[] = new Dish[2];
        d[0] = new Dish("麻婆豆腐", 12);
        d[1] = new Dish("油淋生菜", 9);
//error:                                        d[0].name="麻婆豆腐";d[0].unit_price=12;
//                                              d[1].name="油淋生菜";d[1].unit_price=9;
//text:                                         System.out.println(d[1].name+" "+d[1].unit_price);
        Scanner scanner = new Scanner(System.in);
        String useless = scanner.nextLine();
        int din = 0;
        int tab = 0;
        String[] re = useless.split(" ", 2);
        int pricc = Integer.valueOf(re[1]);
        if (pricc >= 400)
            System.out.println(re[0] + " price out of range 400");
        else {
            d[din] = new Dish(re[0], pricc);
            din++;
        }
        useless = scanner.nextLine();
        String[] re1 = useless.split(" ", 3);
        pricc = Integer.valueOf(re1[1]);
        if (pricc >= 400)
            System.out.println(re1[0] + " price out of range 400");
        else {
            d[din] = new Dish(re1[0], pricc);
            din++;
        }
        String a = scanner.nextLine();// ***
        while (a.indexOf("end") == -1) {
            String[] result1 = a.split(" ", 4);
            if (a.indexOf("table") == -1) {
                System.out.println("wrong format");
                return;
            }
            String[] time = result1[3].split("/");
            int hour = Integer.valueOf(time[0]);
            int min = Integer.valueOf(time[1]);
            int se = Integer.valueOf(time[2]);
            String[] time1 = result1[2].split("/");
            int year = Integer.valueOf(time1[0]);
            int month = Integer.valueOf(time1[1]);
            int day = Integer.valueOf(time1[2]);
            double sale = 0;
            int dayy = 0;
//            String myString = "hello123"; //创建一个字符串变量myString
            char[] my; // 创建一个字符数组myCharArray
            my = result1[1].toCharArray(); // 将字符串变量转换为字符数组
//            for(int i=0; i<myCharArray.length; i++) {
//                System.out.print(myCharArray[i] + " "); //将每个字符打印出来
//            }
            if (my[0] >= 'a' && my[0] <= 'z') {
                System.out.println("wrong format");
                return;
            }
            if (my[0] >= 'A' && my[0] <= 'Z') {
                System.out.println("wrong format");
                return;
            }
            int number = Integer.valueOf(result1[1]);
            if (result1[3].length() != 8 || number > 55 || number <= 0) {
                System.out.println("wrong format");
                return;
            }
            if (judge(year) == 0) {
                System.out.println("not a valid time period");
                return;
            }
//             if (Prt(year, month, dayy) >= 1 && Prt(year, month, dayy) <= 5)
//                 sale = onsale(hour * 3600 + min * 60 + se);
//             else
            sale = 1.00;
            System.out.println(result1[0] + " " + result1[1] + ": ");
            a = scanner.nextLine();
            int i = 0;
            int s = 0;
            Order o[] = new Order[1000];
            int p1 = 0;
//         Order p1 = new Order();
            int p = 0;
            int[] cc = new int[100];
            int cindex = 0;
            while (a.indexOf("end") == -1 && a.indexOf("table") == -1) {
                if (a.indexOf("delete") != -1) {
                    int x = Integer.valueOf(a.substring(0, 1));
                    cc[cindex] = x;
                    cindex++;
                    int flag = 0;
                    if (x == 0) {
                        System.out.println("niho");
                    }
                    for (int db = 0; db < cindex - 1; db++) {
                        if (cc[db] == x) {
                            System.out.println("deduplication " + x);
                            flag = 1;
                            break;
                        }
                    }
                    if (x > i)
                        System.out.println("delete error;");
                    if (x <= i && flag == 0)
                        s = s - o[x - 1].price;
                } else {
                    String[] result = a.split(" ", 4);
                    int j;
                    for (j = 0; j < din; j++) {
                        if (a.indexOf(d[j].name) != -1) {
                            p = d[j].unit_price;
                            break;
                        }
                    }
                    if (j == din)
                        System.out.println(result[1] + " does not exist");
                    else {
                        int n = Integer.valueOf(result[2]);
                        int m = Integer.valueOf(result[3]);
                        int juu = 0;
                        if (n == 1)
                            p1 = p * m;
                        if (n == 2) {
                            double loss = p * 1.5 * m;
                            // double loss = p*1.5*m;
                            p1 = (int) (loss + 0.5);
                        }
                        if (n == 3)
                            p1 = p * 2 * m;
                        o[i] = new Order(result[1], p1);
                        if (n >= 4) {
                            System.out.println(n + " portion out of range 4");
                            juu = 1;
                        }
                        if (m > 15) {
                            System.out.println(result[0] + " num out of range 16");
                            juu = 1;
                        }
                        if (juu == 0) {
                            s = s + p1;
                            System.out.println(result[0] + " " + result[1] + " " + p1);
                        }
                        i++;
                    }
                }
                a = scanner.nextLine();
                if (a.indexOf("table") != -1) {
                    tab = 1;
                    break;
                }
            }
            if (sale != 0) {
                System.out.print(result1[0] + " " + result1[1] + ": ");
                System.out.print(s + " ");
                double sxd = s * sale * 1.0;
                if (Prt(year, month, dayy) >= 1 && Prt(year, month, dayy) <= 5)
                    sxd = sxd * 0.7 + 0.5;
                s = (int) sxd;
                System.out.println(s);
            } else
                System.out.println(result1[0] + " " + result1[1] + " out of opening hours");
        }
    }

    private static int judge(int year) {
        // TODO Auto-generated method stub
        if (year < 2022 || year > 2023)
            return 0;
        return 1;
    }

    public static int Prt(int year, int month, int day) {
        int[] x = new int[12];
        x[0] = 31;
        x[1] = 28;
        x[2] = 31;
        x[3] = 30;
        x[4] = 31;
        x[5] = 30;
        x[6] = 31;
        x[7] = 31;
        x[8] = 30;
        x[9] = 31;
        x[10] = 30;
        x[11] = 31;
        if (LeapYear(year) == 1)
            x[1] = 29;
        int s1 = 0;
        for (int i = 0; i < month - 1; i++)
            s1 = s1 + x[i];
        s1 = s1 + day;
        int c;
        // c = [Y-1] + [(Y-1)/4] - [(Y-1)/100] + [(Y-1)/400] + D
        c = (year - 1 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 + s1) % 7;
        // Y是年份数,D是这一天在这一年中的累积天数,也就是这一天在这一年中是第几天。
        if (c == 0)
            c = 7;
        return c;
    }

    public static int LeapYear(int year) {
        if (year % 4 == 0 && year % 100 != 0)
            return 1;
        if (year % 400 == 0)
            return 1;
        return 0;
    }

    public static double onsale(int x) {
        if (x >= 61200 && x <= 73800)
            return 0.8;
        if (x >= 37800 && x <= 52200)
            return 0.6;
        return 0;
    }
}

class Dish {
    String name;
    int unit_price;

    public Dish() {
    }

    public Dish(String name, int unit_price) {
        this.name = name;
        this.unit_price = unit_price;
    }
}

class Order {
    String name;
    int price;

//     public Order{
//     }
    public Order(String name, int price) {
        this.name = name;
        this.price = price;
    }
}

class Table {

Order order;

int num;

int year;

int month;

int day;

int hour;

int min;

int sec;

int week;

public Table(){

 

}

public boolean check(){

int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

if (month >= 1 && month <= 12) {

//判断是否为闰年

if ((year % 100 == 0 && year % 400 == 0) || year % 4 == 0) {

if (month == 2 && day <= 29) return true;

else {

if (day <= days[month - 1]) return true;

}

} else {

if (day <= days[month - 1])

return true;

}

}

return false;

}

boolean checkorder(int x){

   class Order {

        Record[] records = new Record[100];//保存订单上每一道的记录
        int i=0,s=0;//s为点菜数
        int year;
        int month;
        int day;


        public Order(){

        }


        int getTotalPrice(){
            int num = 0;
            for(i=0;i<s;i++){
                if(records[i].life==0)
                     num = num + records[i].getPrice();
            }
            return num;
        }//计算订单的总价
        int ygetTotalPrice(){
            int num = 0;
            for(i=0;i<s;i++){
                if(records[i].life==0)
                    num = num + records[i].ygetPrice();
            }
            return num;
        }//计算订单的原总价

        public Record addARecord(int orderNum,String dishName,int portion,int num,Menu menu,int week,String name ,String tel){

            for (i=0;i<s;i++){
                if(dishName==records[i].d.name&&portion==records[i].portion) {
                    records[i].num = records[i].num + num;
                    s++;
                    return records[i];
                }
            }
            if(i==s) {

                records[i] = new Record();
                if(menu.searthDish(dishName)!=null) {
                    records[i].d = menu.searthDish(dishName);
                    records[i].orderNum = orderNum;
                    records[i].d.name = dishName;
                    records[i].portion = portion;
                    records[i].num = num;
                    records[i].week = week;
                    records[i].name = name;
                    records[i].tel = tel;
                    s++;
                }
                else {
                    records[i].d = new Dish();
                    records[i].d.name=dishName;
                    records[i].life=6;//订单的菜不存在
                    s++;
                }
                return records[i];
            }
            return null;
        }//添加一条菜品信息到订单中。

        public void delARecordByOrderNum(int orderNum){
            for (i=0;i<s;i++){
                if(records[i].orderNum==orderNum){
                    if(records[i].life==1)
                        records[i].life = 2;
                    else
                        records[i].life = 1;
                }

            }

        }//根据序号删除一条记录

        public int findRecordByNum(int orderNum){
            for (i=0;i<s;i++){
                if (records[i].orderNum==orderNum)
                    return i;
            }
            return -1;
        }//根据序号查找一条记录

    }

 

for(int j=0;j<=order.s-1;j++){

if(x<=order.records[j].orderNum)

return false;

}

return true;

}

 

}

    •   菜单5
    1. 类图

 

 

 

 

 

 

     2.代码

     

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 类名称 对象数组名[] = new 类名称[长度];
        Dish d[] = new Dish[2];
        d[0] = new Dish("麻婆豆腐", 12);
        d[1] = new Dish("油淋生菜", 9);
//error:                                        d[0].name="麻婆豆腐";d[0].unit_price=12;
//                                              d[1].name="油淋生菜";d[1].unit_price=9;
//text:                                         System.out.println(d[1].name+" "+d[1].unit_price);
        Scanner scanner = new Scanner(System.in);
        String useless = scanner.nextLine();
        int din = 0;
        int tab = 0;
        String[] re = useless.split(" ", 2);
        int pricc = Integer.valueOf(re[1]);
        if (pricc >= 400)
            System.out.println(re[0] + " price out of range 400");
        else {
            d[din] = new Dish(re[0], pricc);
            din++;
        }
        useless = scanner.nextLine();
        String[] re1 = useless.split(" ", 3);
        pricc = Integer.valueOf(re1[1]);
        if (pricc >= 400)
            System.out.println(re1[0] + " price out of range 400");
        else {
            d[din] = new Dish(re1[0], pricc);
            din++;
        }
        String a = scanner.nextLine();// ***
        while (a.indexOf("end") == -1) {
            String[] result1 = a.split(" ", 4);
            if (a.indexOf("table") == -1) {
                System.out.println("wrong format");
                return;
            }
            String[] time = result1[3].split("/");
            int hour = Integer.valueOf(time[0]);
            int min = Integer.valueOf(time[1]);
            int se = Integer.valueOf(time[2]);
            String[] time1 = result1[2].split("/");
            int year = Integer.valueOf(time1[0]);
            int month = Integer.valueOf(time1[1]);
            int day = Integer.valueOf(time1[2]);
            double sale = 0;
            int dayy = 0;
//            String myString = "hello123"; //创建一个字符串变量myString
            char[] my; // 创建一个字符数组myCharArray
            my = result1[1].toCharArray(); // 将字符串变量转换为字符数组
//            for(int i=0; i<myCharArray.length; i++) {
//                System.out.print(myCharArray[i] + " "); //将每个字符打印出来
//            }
            if (my[0] >= 'a' && my[0] <= 'z') {
                System.out.println("wrong format");
                return;
            }
            if (my[0] >= 'A' && my[0] <= 'Z') {
                System.out.println("wrong format");
                return;
            }
            int number = Integer.valueOf(result1[1]);
            if (result1[3].length() != 8 || number > 55 || number <= 0) {
                System.out.println("wrong format");
                return;
            }
            if (judge(year) == 0) {
                System.out.println("not a valid time period");
                return;
            }
//             if (Prt(year, month, dayy) >= 1 && Prt(year, month, dayy) <= 5)
//                 sale = onsale(hour * 3600 + min * 60 + se);
//             else
            sale = 1.00;
            System.out.println(result1[0] + " " + result1[1] + ": ");
            a = scanner.nextLine();
            int i = 0;
            int s = 0;
            Order o[] = new Order[1000];
            int p1 = 0;
//         Order p1 = new Order();
            int p = 0;
            int[] cc = new int[100];
            int cindex = 0;
            while (a.indexOf("end") == -1 && a.indexOf("table") == -1) {
                if (a.indexOf("delete") != -1) {
                    int x = Integer.valueOf(a.substring(0, 1));
                    cc[cindex] = x;
                    cindex++;
                    int flag = 0;
                    if (x == 0) {
                        System.out.println("niho");
                    }
                    for (int db = 0; db < cindex - 1; db++) {
                        if (cc[db] == x) {
                            System.out.println("deduplication " + x);
                            flag = 1;
                            break;
                        }
                    }
                    if (x > i)
                        System.out.println("delete error;");
                    if (x <= i && flag == 0)
                        s = s - o[x - 1].price;
                } else {
                    String[] result = a.split(" ", 4);
                    int j;
                    for (j = 0; j < din; j++) {
                        if (a.indexOf(d[j].name) != -1) {
                            p = d[j].unit_price;
                            break;
                        }
                    }
                    if (j == din)
                        System.out.println(result[1] + " does not exist");
                    else {
                        int n = Integer.valueOf(result[2]);
                        int m = Integer.valueOf(result[3]);
                        int juu = 0;
                        if (n == 1)
                            p1 = p * m;
                        if (n == 2) {
                            double loss = p * 1.5 * m;
                            // double loss = p*1.5*m;
                            p1 = (int) (loss + 0.5);
                        }
                        if (n == 3)
                            p1 = p * 2 * m;
                        o[i] = new Order(result[1], p1);
                        if (n >= 4) {
                            System.out.println(n + " portion out of range 4");
                            juu = 1;
                        }
                        if (m > 15) {
                            System.out.println(result[0] + " num out of range 16");
                            juu = 1;
                        }
                        if (juu == 0) {
                            s = s + p1;
                            System.out.println(result[0] + " " + result[1] + " " + p1);
                        }
                        i++;
                    }
                }
                a = scanner.nextLine();
                if (a.indexOf("table") != -1) {
                    tab = 1;
                    break;
                }
            }
            if (sale != 0) {
                System.out.print(result1[0] + " " + result1[1] + ": ");
                System.out.print(s + " ");
                double sxd = s * sale * 1.0;
                if (Prt(year, month, dayy) >= 1 && Prt(year, month, dayy) <= 5)
                    sxd = sxd * 0.7 + 0.5;
                s = (int) sxd;
                System.out.println(s);
            } else
                System.out.println(result1[0] + " " + result1[1] + " out of opening hours");
        }
    }

    private static int judge(int year) {
        // TODO Auto-generated method stub
        if (year < 2022 || year > 2023)
            return 0;
        return 1;
    }

    public static int Prt(int year, int month, int day) {
        int[] x = new int[12];
        x[0] = 31;
        x[1] = 28;
        x[2] = 31;
        x[3] = 30;
        x[4] = 31;
        x[5] = 30;
        x[6] = 31;
        x[7] = 31;
        x[8] = 30;
        x[9] = 31;
        x[10] = 30;
        x[11] = 31;
        if (LeapYear(year) == 1)
            x[1] = 29;
        int s1 = 0;
        for (int i = 0; i < month - 1; i++)
            s1 = s1 + x[i];
        s1 = s1 + day;
        int c;
        // c = [Y-1] + [(Y-1)/4] - [(Y-1)/100] + [(Y-1)/400] + D
        c = (year - 1 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 + s1) % 7;
        // Y是年份数,D是这一天在这一年中的累积天数,也就是这一天在这一年中是第几天。
        if (c == 0)
            c = 7;
        return c;
    }

    public static int LeapYear(int year) {
        if (year % 4 == 0 && year % 100 != 0)
            return 1;
        if (year % 400 == 0)
            return 1;
        return 0;
    }

    public static double onsale(int x) {
        if (x >= 61200 && x <= 73800)
            return 0.8;
        if (x >= 37800 && x <= 52200)
            return 0.6;
        return 0;
    }
}

class Dish {
    String name;
    int unit_price;

    public Dish() {
    }

    public Dish(String name, int unit_price) {
        this.name = name;
        this.unit_price = unit_price;
    }
}

class Order {
    String name;
    int price;

//     public Order{
//     }
    public Order(String name, int price) {
        this.name = name;
        this.price = price;
    }
}

class Table {

Order order;

int num;

int year;

int month;

int day;

int hour;

int min;

int sec;

int week;

public Table(){

 

}

public boolean check(){

int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

if (month >= 1 && month <= 12) {

//判断是否为闰年

if ((year % 100 == 0 && year % 400 == 0) || year % 4 == 0) {

if (month == 2 && day <= 29) return true;

else {

if (day <= days[month - 1]) return true;

}

} else {

if (day <= days[month - 1])

return true;

}

}

return false;

}

boolean checkorder(int x){

   class Order {

        Record[] records = new Record[100];//保存订单上每一道的记录
        int i=0,s=0;//s为点菜数
        int year;
        int month;
        int day;


        public Order(){

        }


        int getTotalPrice(){
            int num = 0;
            for(i=0;i<s;i++){
                if(records[i].life==0)
                     num = num + records[i].getPrice();
            }
            return num;
        }//计算订单的总价
        int ygetTotalPrice(){
            int num = 0;
            for(i=0;i<s;i++){
                if(records[i].life==0)
                    num = num + records[i].ygetPrice();
            }
            return num;
        }//计算订单的原总价

        public Record addARecord(int orderNum,String dishName,int portion,int num,Menu menu,int week,String name ,String tel){

            for (i=0;i<s;i++){
                if(dishName==records[i].d.name&&portion==records[i].portion) {
                    records[i].num = records[i].num + num;
                    s++;
                    return records[i];
                }
            }
            if(i==s) {

                records[i] = new Record();
                if(menu.searthDish(dishName)!=null) {
                    records[i].d = menu.searthDish(dishName);
                    records[i].orderNum = orderNum;
                    records[i].d.name = dishName;
                    records[i].portion = portion;
                    records[i].num = num;
                    records[i].week = week;
                    records[i].name = name;
                    records[i].tel = tel;
                    s++;
                }
                else {
                    records[i].d = new Dish();
                    records[i].d.name=dishName;
                    records[i].life=6;//订单的菜不存在
                    s++;
                }
                return records[i];
            }
            return null;
        }//添加一条菜品信息到订单中。

        public void delARecordByOrderNum(int orderNum){
            for (i=0;i<s;i++){
                if(records[i].orderNum==orderNum){
                    if(records[i].life==1)
                        records[i].life = 2;
                    else
                        records[i].life = 1;
                }

            }

        }//根据序号删除一条记录

        public int findRecordByNum(int orderNum){
            for (i=0;i<s;i++){
                if (records[i].orderNum==orderNum)
                    return i;
            }
            return -1;
        }//根据序号查找一条记录

    }

 

for(int j=0;j<=order.s-1;j++){

if(x<=order.records[j].orderNum)

return false;

}

return true;

}

 

}

 
    •  菜单6

    2.代码

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 类名称 对象数组名[] = new 类名称[长度];
        Dish d[] = new Dish[2];
        d[0] = new Dish("麻婆豆腐", 12);
        d[1] = new Dish("油淋生菜", 9);
//error:                                        d[0].name="麻婆豆腐";d[0].unit_price=12;
//                                              d[1].name="油淋生菜";d[1].unit_price=9;
//text:                                         System.out.println(d[1].name+" "+d[1].unit_price);
        Scanner scanner = new Scanner(System.in);
        String useless = scanner.nextLine();
        int din = 0;
        int tab = 0;
        String[] re = useless.split(" ", 2);
        int pricc = Integer.valueOf(re[1]);
        if (pricc >= 400)
            System.out.println(re[0] + " price out of range 400");
        else {
            d[din] = new Dish(re[0], pricc);
            din++;
        }
        useless = scanner.nextLine();
        String[] re1 = useless.split(" ", 3);
        pricc = Integer.valueOf(re1[1]);
        if (pricc >= 400)
            System.out.println(re1[0] + " price out of range 400");
        else {
            d[din] = new Dish(re1[0], pricc);
            din++;
        }
        String a = scanner.nextLine();// ***
        while (a.indexOf("end") == -1) {
            String[] result1 = a.split(" ", 4);
            if (a.indexOf("table") == -1) {
                System.out.println("wrong format");
                return;
            }
            String[] time = result1[3].split("/");
            int hour = Integer.valueOf(time[0]);
            int min = Integer.valueOf(time[1]);
            int se = Integer.valueOf(time[2]);
            String[] time1 = result1[2].split("/");
            int year = Integer.valueOf(time1[0]);
            int month = Integer.valueOf(time1[1]);
            int day = Integer.valueOf(time1[2]);
            double sale = 0;
            int dayy = 0;
//            String myString = "hello123"; //创建一个字符串变量myString
            char[] my; // 创建一个字符数组myCharArray
            my = result1[1].toCharArray(); // 将字符串变量转换为字符数组
//            for(int i=0; i<myCharArray.length; i++) {
//                System.out.print(myCharArray[i] + " "); //将每个字符打印出来
//            }
            if (my[0] >= 'a' && my[0] <= 'z') {
                System.out.println("wrong format");
                return;
            }
            if (my[0] >= 'A' && my[0] <= 'Z') {
                System.out.println("wrong format");
                return;
            }
            int number = Integer.valueOf(result1[1]);
            if (result1[3].length() != 8 || number > 55 || number <= 0) {
                System.out.println("wrong format");
                return;
            }
            if (judge(year) == 0) {
                System.out.println("not a valid time period");
                return;
            }
//             if (Prt(year, month, dayy) >= 1 && Prt(year, month, dayy) <= 5)
//                 sale = onsale(hour * 3600 + min * 60 + se);
//             else
            sale = 1.00;
            System.out.println(result1[0] + " " + result1[1] + ": ");
            a = scanner.nextLine();
            int i = 0;
            int s = 0;
            Order o[] = new Order[1000];
            int p1 = 0;
//         Order p1 = new Order();
            int p = 0;
            int[] cc = new int[100];
            int cindex = 0;
            while (a.indexOf("end") == -1 && a.indexOf("table") == -1) {
                if (a.indexOf("delete") != -1) {
                    int x = Integer.valueOf(a.substring(0, 1));
                    cc[cindex] = x;
                    cindex++;
                    int flag = 0;
                    if (x == 0) {
                        System.out.println("niho");
                    }
                    for (int db = 0; db < cindex - 1; db++) {
                        if (cc[db] == x) {
                            System.out.println("deduplication " + x);
                            flag = 1;
                            break;
                        }
                    }
                    if (x > i)
                        System.out.println("delete error;");
                    if (x <= i && flag == 0)
                        s = s - o[x - 1].price;
                } else {
                    String[] result = a.split(" ", 4);
                    int j;
                    for (j = 0; j < din; j++) {
                        if (a.indexOf(d[j].name) != -1) {
                            p = d[j].unit_price;
                            break;
                        }
                    }
                    if (j == din)
                        System.out.println(result[1] + " does not exist");
                    else {
                        int n = Integer.valueOf(result[2]);
                        int m = Integer.valueOf(result[3]);
                        int juu = 0;
                        if (n == 1)
                            p1 = p * m;
                        if (n == 2) {
                            double loss = p * 1.5 * m;
                            // double loss = p*1.5*m;
                            p1 = (int) (loss + 0.5);
                        }
                        if (n == 3)
                            p1 = p * 2 * m;
                        o[i] = new Order(result[1], p1);
                        if (n >= 4) {
                            System.out.println(n + " portion out of range 4");
                            juu = 1;
                        }
                        if (m > 15) {
                            System.out.println(result[0] + " num out of range 16");
                            juu = 1;
                        }
                        if (juu == 0) {
                            s = s + p1;
                            System.out.println(result[0] + " " + result[1] + " " + p1);
                        }
                        i++;
                    }
                }
                a = scanner.nextLine();
                if (a.indexOf("table") != -1) {
                    tab = 1;
                    break;
                }
            }
            if (sale != 0) {
                System.out.print(result1[0] + " " + result1[1] + ": ");
                System.out.print(s + " ");
                double sxd = s * sale * 1.0;
                if (Prt(year, month, dayy) >= 1 && Prt(year, month, dayy) <= 5)
                    sxd = sxd * 0.7 + 0.5;
                s = (int) sxd;
                System.out.println(s);
            } else
                System.out.println(result1[0] + " " + result1[1] + " out of opening hours");
        }
    }

    private static int judge(int year) {
        // TODO Auto-generated method stub
        if (year < 2022 || year > 2023)
            return 0;
        return 1;
    }

    public static int Prt(int year, int month, int day) {
        int[] x = new int[12];
        x[0] = 31;
        x[1] = 28;
        x[2] = 31;
        x[3] = 30;
        x[4] = 31;
        x[5] = 30;
        x[6] = 31;
        x[7] = 31;
        x[8] = 30;
        x[9] = 31;
        x[10] = 30;
        x[11] = 31;
        if (LeapYear(year) == 1)
            x[1] = 29;
        int s1 = 0;
        for (int i = 0; i < month - 1; i++)
            s1 = s1 + x[i];
        s1 = s1 + day;
        int c;
        // c = [Y-1] + [(Y-1)/4] - [(Y-1)/100] + [(Y-1)/400] + D
        c = (year - 1 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 + s1) % 7;
        // Y是年份数,D是这一天在这一年中的累积天数,也就是这一天在这一年中是第几天。
        if (c == 0)
            c = 7;
        return c;
    }

    public static int LeapYear(int year) {
        if (year % 4 == 0 && year % 100 != 0)
            return 1;
        if (year % 400 == 0)
            return 1;
        return 0;
    }

    public static double onsale(int x) {
        if (x >= 61200 && x <= 73800)
            return 0.8;
        if (x >= 37800 && x <= 52200)
            return 0.6;
        return 0;
    }
}

class Dish {
    String name;
    int unit_price;

    public Dish() {
    }

    public Dish(String name, int unit_price) {
        this.name = name;
        this.unit_price = unit_price;
    }
}

class Order {
    String name;
    int price;

//     public Order{
//     }
    public Order(String name, int price) {
        this.name = name;
        this.price = price;
    }
}
class Table {

Order order;

int num;

int year;

int month;

int day;

int hour;

int min;

int sec;

int week;

public Table(){

 

}

public boolean check(){

int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

if (month >= 1 && month <= 12) {

//判断是否为闰年

if ((year % 100 == 0 && year % 400 == 0) || year % 4 == 0) {

if (month == 2 && day <= 29) return true;

else {

if (day <= days[month - 1]) return true;

}

} else {

if (day <= days[month - 1])

return true;

}

}

return false;

}

boolean checkorder(int x){

   class Order {

        Record[] records = new Record[100];//保存订单上每一道的记录
        int i=0,s=0;//s为点菜数
        int year;
        int month;
        int day;


        public Order(){

        }


        int getTotalPrice(){
            int num = 0;
            for(i=0;i<s;i++){
                if(records[i].life==0)
                     num = num + records[i].getPrice();
            }
            return num;
        }//计算订单的总价
        int ygetTotalPrice(){
            int num = 0;
            for(i=0;i<s;i++){
                if(records[i].life==0)
                    num = num + records[i].ygetPrice();
            }
            return num;
        }//计算订单的原总价

        public Record addARecord(int orderNum,String dishName,int portion,int num,Menu menu,int week,String name ,String tel){

            for (i=0;i<s;i++){
                if(dishName==records[i].d.name&&portion==records[i].portion) {
                    records[i].num = records[i].num + num;
                    s++;
                    return records[i];
                }
            }
            if(i==s) {

                records[i] = new Record();
                if(menu.searthDish(dishName)!=null) {
                    records[i].d = menu.searthDish(dishName);
                    records[i].orderNum = orderNum;
                    records[i].d.name = dishName;
                    records[i].portion = portion;
                    records[i].num = num;
                    records[i].week = week;
                    records[i].name = name;
                    records[i].tel = tel;
                    s++;
                }
                else {
                    records[i].d = new Dish();
                    records[i].d.name=dishName;
                    records[i].life=6;//订单的菜不存在
                    s++;
                }
                return records[i];
            }
            return null;
        }//添加一条菜品信息到订单中。

        public void delARecordByOrderNum(int orderNum){
            for (i=0;i<s;i++){
                if(records[i].orderNum==orderNum){
                    if(records[i].life==1)
                        records[i].life = 2;
                    else
                        records[i].life = 1;
                }

            }

        }//根据序号删除一条记录

        public int findRecordByNum(int orderNum){
            for (i=0;i<s;i++){
                if (records[i].orderNum==orderNum)
                    return i;
            }
            return -1;
        }//根据序号查找一条记录

    }
 

for(int j=0;j<=order.s-1;j++){

if(x<=order.records[j].orderNum)

return false;

}

return true;

}

 

}

 

 

  •  踩坑心得
    • 非菜单中的踩坑:
    1. 在题目集二中一开始我认为只要算出来几月几日是这一年的第多少天然后再用这个第多少天%7的结果就是星期几,后来我发现有测试点一直过不了,然后翻了下日历才发现原来不是每年的1月1日都是星期一...改进方法是去csdn了搜了一下得了个简单的计算公式:

           c = [Y-1] + [(Y-1)/4] - [(Y-1)/100] + [(Y-1)/400] + D

           Y是年份数,D是这一天在这一年中的累积天数,也就是这一天在这一年中是第几天。

     2.在题目集三中(7-3 去掉重复的数据),有一个测试点死活过不了,后来才知道是因为一个数据一个数据读太耗时了,最后选择将整个字符串读下来再进行操作解决了该问题

                  Scanner sc = new Scanner(System.in);

            String str = sc.nextLine();

            String[] arr = str.split(" ");

     3.另外就是封装性那道题目,因为上学期写C语言PTA函数题的影响(上学期写的函数题都是主体题目给了,只需要在PTA里补写函数体就可以了)导致我把所有类都写好了还是过不了,最后才发现是要把题干给的主体复制过去才行

    • 菜单中的踩坑:

    先看一下图片就知道踩了多少坑了

  

 

 

 

 

 

                                             

      1.没有对字符串做解析,这个问题是我后面(菜单四)才意识到的,导致代码很混乱,很没用条理,而且没有办法通过一些测试点(比如混乱输入之类的),我写的就是一个大循环读到end结束下套个小循环,小循环读到没有Table结束,出来就是读点菜,读到有delet就进行删除操作,但是这么写的话有一个以上的Table就会很难用

      2.折扣的计算十分混乱,我一开始用的方法是这样的,给一个乘以折扣(或者中份乘以1.5)的数据+0.5,再对他强制类型转换,这样小数位大于等于5的就会进一,反之则不进(但是这样写很麻烦不说,我菜单一还因为这么写过不了一个测试点),现在回头看看,为什么当初我不用Math.round()....

      3.对甜辣度菜系无法处理

  • 主要困难以及改进建议
    • 困难:主要的困难就是来自于菜单,菜单要一口气写出一个体系,可以过所有测试点的体系,但是不是所有测试点都是已知,而且对输入数据要求十分苛刻(有很多测试点都是特殊例子或者不按规定的输入)导致要考虑的特殊情形过多,并且菜单在PTA结束后也没有标准题解或者讲解,导致后面菜单4-5更无从下手
    • 改进建议:
      •   于我自己:应该多花时间在PTA作业上,这样不至于最后几天赶菜单来不及导致分数过低,应该注意代码简洁,能写类的尽量写类,能写方法的尽量写方法,对数据处理要敏感,对特殊情形处理要有条理按次序
      •   于老师:应该及时讲解题目或者发布相关测试点或标准题解,这样不至于让学生做完一次下一次还是这么差,我做了这么多菜单但是因为一直一知半解所以除了低分外更是一点进步没有,其次,PTA发布题目大多与所学知识没有关联,比如讲了抽象类应该让同学做几道相关的题目进行巩固而不是继续发布菜单升级版。还有,比如去重容器set,dp动态规划这些根本在课上都从未涉及过,不知道为什么要出现在PTA题目集中
  • 总结

      其实上面该总结的都总结的差不多了,最后还要说的话就是自己在java上面花的时间其实不算多,上课其实听的还挺认真的,但是下课回去因为没有相关练习,自己也不会主动去把上课那些东西再敲一遍,导致其实相关知识掌握的如何我自己都没有什么把握,对“面对对象编程”其实还是不太了解其内核本质,这样就比较可怕了,java比上学期c语言要难的多,但是更加智能,用起来更加方便,而我花点时间却远不如上学期那般,其中有各种原因而搁置了相关的学习,还是要踏踏实实去做的未来!!!

      要说学到了什么,上课学到了很多,CSDN上学到了很多,但从PTA(主要是菜单)中其实没有多大收获,(反而最大的收获还是那道时间题,写出来高兴了很久),可能我一开始也不是很想写菜单把(毕竟刚做完C语言课设不久),归根结底还是态度上有问题,应该改正。

标签:int,31,System,month,BLOG,year,out
From: https://www.cnblogs.com/rrringo/p/17517805.html

相关文章

  • BLOG-2
    一.前言1.第四次题目集①知识点:啥都考了。②题量:少。③难度:很难。2.第五次题目集①知识点:啥都考了。②题量:少。③难度:难上加难。3.期中考试①知识点:Java基础语法:例如变量定义、常量定义、数据类型、循环、条件语句等。 面向对象编程:例如类和对象的定义,封装、继承和多态......
  • Blog2
    一、前言1.题量及难度这几次作业的题量适中,题目数量适中,不过也不过少,能够提供足够的练习机会。在PTA上的大作业中,一共有三道题。其中第一题和第三题难度不大,但第二题属于点线形系列的题目,是之前得分不高的PTA作业中的重点题型,占据了70分,而我只得到了39分。在期中考试中虽然只有......
  • 4-5次PTA题目总结blog
    前言:题目集1~3的知识点、题量、难度等情况如下:知识点:JAVA基础,基础算法,面向对象程序设计题量:共计2道题目难度:题目从易到难,逐层递进,分别为考察Java各个类的理解、掌握与运用。设计与分析:1importjava.text.ParseException;2importjava.time.DateTimeExce......
  • BLOG-2
    BLOG-2前言这次blog是关于pta题目集4-6和期中考试的总结,菜单计价系统还是挺难的,而期中考试就较为简单,题量也不大,但就是很耗时间。7-1菜单计价程序-4分数 100全屏浏览题目切换布局作者 蔡轲单位 南昌航空大学本体大部分内容与菜单计价程序-3相同,增加的部分用加粗文字......
  • BLOG-2
    一、前言(要写3000个字还是很累的,希望互评能给高点分,我给所有人都是95以上的!)对于pta4和pta5不想多说,点菜系列巅峰之作两题难度都非常大,而且很复杂,写很多次也没啥分,题量也大关于期中考试,难度到不大,主要考察继承多态接口什么的,题量还可以,就是要在规定时间内写完有点紧张二......
  • BLOG-2
    考试分析:个人感觉本次考试难度偏简单,也无需注意些什么,只要仔细读题问题应该都不大; 1.创建一个圆形类(Circle),私有属性为圆的半径,从控制台输入圆的半径,输出圆的面积输入格式:输入圆的半径,取值范围为(0,+∞),输入数据非法,则程序输出WrongFormat,注意:只考虑从控制台输入数值的情况......
  • BLOG2-PTA题目集4、5以及期中考试
    (1)前言本次博客主要涵盖了Java题目的几个主要知识点,包括:1.面向对象的基础知识:这部分主要包括了类和对象的基本概念,构造方法,访问权限和成员变量的相关内容。在面向对象编程中,对这些基础知识的理解至关重要。2.面向对象的设计原则:这个题目强调了两个重要的设计原则,即继承和组......
  • BLOG-2
    前言:这两次PTA4与5都是菜单计价系统的续集,并且都是PTA3的不同迭代的代码,所以需要对PTA3进行不同的修改来完成题目要求。PTA4:由于时间等诸多原因,我并没有完成PTA4上的任务,并且没有在PTA4上及时的提交代码,所以我无法附上我PTA4的源码,但是我将对菜单计价系统4的题目进行分析设计,......
  • Blog - 2
    前言题目量和难度我觉得觉得作业题量适中,不会太多也不会太少,能让我练习。这次大作业,一共三道题。第一题和第三题难度不大,但是第二题是点菜系列的题目,这道题占了70分,而我只拿到了60分。在期中考中,虽然有三道题,但难度不算太大,每一道题都是在前一道题的基础上稍加修改即可。实验一......
  • oo第二次BLOG
    一:总结  pta4,5和期中的作业其实主要用于对所学知识的练习,第六次作业只有一到成绩题目有一定的难度,后两次作业的题目这相对简单一些。作业尽力去完成,虽然有些不完美,但已经尽了全力。七,八次作业折相对简单一些,完成情况也相对好一点。二:作业实现7-1菜单计价程序-4......