- 前言
- 知识点:期中考试主要考察了,继承,抽象类,多态,Comparable接口
- 题量 :还可以
- 难度:很简单
- 设计与分析
- 菜单4
- 类图
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
- 类图
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; } }
- 踩坑心得
- 非菜单中的踩坑:
- 在题目集二中一开始我认为只要算出来几月几日是这一年的第多少天然后再用这个第多少天%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