首页 > 其他分享 >题目集4~6的总结性Blog2

题目集4~6的总结性Blog2

时间:2023-04-28 21:11:48浏览次数:49  
标签:总结性 题目 int Blog2 System splitedStr public order out

目录

  1、前言

  2、设计与分析

  3、踩坑心得

  4、改进建议

  5、总结

题目集4:

1、菜单计价程序-3

2、有重复数据

3、去掉重复数据

4、单词系统与排序

5、面向对象编程(封装性)

6、GPS测绘中度分秒转换

7、判断两个日期的先后、计算间隔天数、周数

 

题目集5:

1、正则表达式训练-QQ号校验

2、字符串训练-字符排序

3、正则表达式训练-验证码校验

4、正则表达式训练-学号校验

5、日期问题面向对象设计(聚合一)

6、日期问题面向对象设计(聚合二)

 

题目集6:

1、菜单计价程序-4

 

1、前言

   本次题目集与前三次相比难了许多,题目集四的许多程序需要我们用到容器,才能用较为简单的方法解决里面的大部分题目,题目集五有正则表达式的几道训练题,让我发现了正则表达式是一个处理字符串十分强大的工具,因此,在写题目集六时,我大量的使用到了正则表达式去处理输入的字符串。题目集四与题目集六的菜单计价程序,难度固然大,但是我认为,如果我能腾出足够的时间的话,多花一点时间与同学交换意见,我应该是能过大部分的测试点的,因为做到了后期,我的程序基本能够运行,有些测试点可能只是输出顺序的问题,具体的问题会在设计与分析之中提到。

2、设计与分析

去掉重复数据

  关于这道题,我是被折磨了许久,因为这题有十万个数据,数据量比较大,因此我最后的三个测试点总是过不了,这题如果我没有记错的话,卡了我三天,我想尽了各种方法去优化我的代码,从最开始的用数组,到用容器,再到最后的使用迭代器输出,在发现问题之前我还一直以为是我的算法不到位,到了最后才知道原来是输出的问题

这是我第一次提交的代码以及pta给我反馈的结果

 

 1 import java.util.*;
 2 
 3 public class Main {
 4 
 5     public static void main(String[] args) {
 6         int n, i, k=0;
 7         Scanner input = new Scanner(System.in);
 8         n = input.nextInt();
 9         int[] numArray = new int[n];
10         int[] array_2 = new int[100001];//记录重复数据是否输出
11         int[] newNumArray = new int[n];
12         Arrays.fill(array_2, 0);
13         for (i = 0; i < n; i++) {
14             numArray[i] = input.nextInt();
15         }
16         array_2[numArray[0]]++;
17         newNumArray[0] = numArray[0];
18         for (i = 0; i < n; i++){
19             if (array_2[numArray[i]] == 0){
20                 System.out.printf("%d ",newNumArray[k]);
21                 k++;
22                 newNumArray[k] = numArray[i];
23                 array_2[numArray[i]]++;
24             }
25         }
26         System.out.printf("%d",newNumArray[k]);
27     }
28 }

 

可以看到,源码是单层循环,但是却有三个点报出超时,这就麻烦了啊,单层循环还超时,那可能是数组这个方法太Low了?要用容器解决?所以我上CSDN学习了一下容器的使用,看了几篇关于容器的文章,我看到我看到一种能完美解决这个题目的容器,那就是Set(集合),因为集合里面的元素是不重复的,因此可以省略去除重复的操作,如果这题能用集合去写,那肯定能够简化我的代码。然后看到LinkHashset能够保留输入的顺序,那么解决在我能力范围之内的最好方法就是LinkedHashSet了!

这是我使用了容器和迭代器输出的代码以及pta反馈的结果:

 

 1 import java.util.*;
 2 
 3 public class Main{
 4     public static void main(String[] args) {
 5         Set<Integer> numSet = new LinkedHashSet<>();
 6         Scanner input = new Scanner(System.in);
 7         int i,n = input.nextInt();
 8         for (i = 0; i < n; i++){
 9             numSet.add(input.nextInt());
10         }
11         Iterator<Integer> iterator = numSet.iterator();
12         for (i = 0; i < numSet.size() - 1 && iterator.hasNext(); i++){
13             System.out.printf("%d ",iterator.next());
14         }
15         System.out.printf("%d",iterator.next());
16     }
17 }

 

 

 

 可以看到最后还是报了一个超时的错误,这就让我非常迷惑了,我问了其他同学怎么写,他们用容器或者用数组,只要不是单层循环的都写对了这题,那为什么我过不了啊

最后也不晓得是为什么,把代码改成了这个样子,测试点就全过了???

 

 1 import java.util.*;
 2 
 3 public class Main {
 4     public static void main(String[] args) {
 5         Scanner input = new Scanner(System.in);
 6         Set<Integer> numSet = new LinkedHashSet<>();
 7         int n = input.nextInt();
 8         for (int i = 0 ; i < n;i++){
 9             numSet.add(input.nextInt());
10         }
11         Iterator<Integer> iterator = numSet.iterator();
12         for (int i = 0; i < numSet.size() - 1 && iterator.hasNext();i++){
13             System.out.print(iterator.next()+" ");
14         }
15         System.out.print(iterator.next());
16     }
17 }

 

 

 

也就是把之前的println改成了print就对了?我后面把我第一次用数组写的代码也改了一下输出交了上去,最后也是过了所有的测试点。没想到到头来是输出出了问题,亏我还不断优化我的算法和代码,但是这也算是买个教训吧,以后我是再也不会因为printf用的熟悉去用printf了。

单词系统与排序

  这道题最大的难点应该就是重写单词的排序方法了,因为题目要求我们不仅要根据单词的长度比大小,还要在相同长度的情况下忽略单词的大小写进行比较。之前写第三题的时候我已经了解到了TreeSet可以对输入的元素进行排序,并且可以去除重复的元素,但是排序的方法大概率是不符合题目要求的,那怎么办呢。。。如果没记错的话,书上好像有对Comparable的接口进行讲解,如果TreeSet可以对输入的元素进行排序,那么它必定有Compartor接口,所以我的任务就是对它进行重写就好了!

以下是本题的源码:

 

 1 import java.util.*;
 2 
 3 public class Main{
 4     public static void main(String[] args){
 5         Scanner input = new Scanner(System.in);
 6         String sentence = input.nextLine();
 7         String[] word = sentence.split(",| |\\.");
 8         TreeSet<String> sortedWord = new TreeSet<>(new newComparator());
 9         int i;
10         for (i = 0;i < word.length;i++){
11             if (!word[i].equals("")) {
12                 sortedWord.add(word[i]);
13             }
14         }
15         Iterator<String> iterator = sortedWord.iterator();
16         while (iterator.hasNext()){
17             System.out.println(iterator.next());
18         }
19     }
20 }
21 class newComparator implements Comparator<String>{//重写排序方法
22     @Override
23     public int compare(String str1,String str2){
24         if (str1.length() > str2.length()){
25             return -1;
26         }else if (str1.length() == str2.length()){
27             return str1.compareToIgnoreCase(str2);//无视大小写进行比较
28         }else{
29             return 1;
30         }
31     }
32 }

 

  可以看到Java还非常贴心的给我们准备了一个忽略大小写比较字符串的函数,完美符合本题的要求。第七行分割字符我使用了正则表达式,只要见到","" ""."就对字符进行分割,并且因为.为元字符,所以需要加双斜杠对.进行转义。

日期问题面向对象设计(聚合一)

  本题大部分的算法其实在题目集3已经实现了,这道题主要的目的应该是想让我们理解并且练习一下依赖关系。刚刚开始写这道题时,因为是第一次使用依赖关系写代码,所以该如何操作以及访问个各类的属性还不是很熟练,所以做聚合一这道题目的时候花的时间还是比较多的。但是理解之后发现发现实现起来还是蛮简单的,本质就是以类作为属性,然后通过这个属性,调用get方法来访问这个类的属性。理解了之后这道题目就好写多了,而且这道题类与类之间的关系设计的非常巧妙,每个类之间只能通过与它聚合的类来访问它的方法,符合迪米特法则“只与直接朋友联系”。

 

  1 import java.util.*;
  2 public class Main {
  3     public static void main(String[] args){
  4         Scanner input = new Scanner(System.in);
  5         int year = 0;
  6         int month = 0;
  7         int day = 0;
  8 
  9         int choice = input.nextInt();
 10         if (choice == 1){
 11             int m = 0;
 12             year = Integer.parseInt(input.next());
 13             month = Integer.parseInt(input.next());
 14             day = Integer.parseInt(input.next());
 15 
 16             DateUtil date = new DateUtil(day, month, year);
 17 
 18             if (date.checkInputValidity()) {
 19                 System.out.println("Wrong Format");
 20                 System.exit(0);
 21             }
 22             m = input.nextInt();
 23             System.out.println(date.getNextNDays(m).showDate());
 24         }else if (choice == 2){
 25             int n = 0;
 26             year = Integer.parseInt(input.next());
 27             month = Integer.parseInt(input.next());
 28             day = Integer.parseInt(input.next());
 29 
 30             DateUtil date = new DateUtil(day, month, year);
 31 
 32             if (date.checkInputValidity()) {
 33                 System.out.println("Wrong Format");
 34                 System.exit(0);
 35             }
 36 
 37             n = input.nextInt();
 38 
 39             if (n < 0) {
 40                 System.out.println("Wrong Format");
 41                 System.exit(0);
 42             }
 43             System.out.println(date.getPreviousNDays(n).showDate());
 44         }else if (choice == 3){
 45             year = Integer.parseInt(input.next());
 46             month = Integer.parseInt(input.next());
 47             day = Integer.parseInt(input.next());
 48 
 49             int anotherYear = Integer.parseInt(input.next());
 50             int anotherMonth = Integer.parseInt(input.next());
 51             int anotherDay = Integer.parseInt(input.next());
 52 
 53             DateUtil fromDate = new DateUtil(day, month, year);
 54             DateUtil toDate = new DateUtil(anotherDay, anotherMonth, anotherYear);
 55 
 56             if (!fromDate.checkInputValidity() && !toDate.checkInputValidity()) {
 57                 System.out.println(fromDate.getDaysofDates(toDate));
 58             } else {
 59                 System.out.println("Wrong Format");
 60                 System.exit(0);
 61             }
 62         }else{
 63             System.out.println("Wrong Format");
 64             System.exit(0);
 65         }
 66     }
 67 }
 68 class DateUtil{
 69     private Day day;//使用带参数的构造方法
 70     int d;
 71     int m;
 72     int y;
 73     public DateUtil() {
 74 
 75     }
 76     public DateUtil(int d,int m,int y){
 77         this.d = d;
 78         this.m = m;
 79         this.y = y;
 80         day = new Day(this.y,this.m,this.d);
 81         this.day.setValue(d);
 82     }
 83 
 84     public Day getDay() {
 85         return this.day;
 86     }
 87 
 88     public void setDay(Day d) {
 89         this.day = d;
 90     }
 91 
 92     public boolean compareDates(DateUtil date){//比较两天大小
 93         if (this.y < date.y) {
 94             return true;
 95         } else if (this.m < date.m && date.y == this.y) {
 96             return true;
 97         } else if (this.d < date.d && this.m == date.m && date.y == this.y) {
 98             return true;
 99         } else {
100             return false;
101         }
102     }
103 
104     public boolean equalTwoDates(DateUtil date) {//判断两天是否相等
105         if ((this.y == date.y) && (m == date.m) && (this.d == date.d)) {
106             return true;
107         } else {
108             return false;
109         }
110     }
111 
112     public boolean checkInputValidity(){
113         DateUtil Date = new DateUtil(d,m,y);
114         int[] mon_maxnum = Date.getDay().getMon_maxnum();
115         if (Date.getDay().getMonth().getYear().isLeapYear()){
116             mon_maxnum[2] = 29;
117         }else{
118             mon_maxnum[2] = 28;
119         }
120         if ((this.y >= 1900 && this.y <= 2050) && (this.m >= 1 && this.m <= 12) && (this.d >= 1 && this.d <= mon_maxnum[this.m])){
121             return false;
122         }else{
123             return true;
124         }
125     }
126 
127     public String showDate(){//输出日期
128         return this.day.getMonth().getYear().getValue()+"-"+this.day.getMonth().getValue()+"-"+this.day.getValue();
129     }
130 
131     public DateUtil getNextNDays(int n){//求下n天
132         DateUtil Date = new DateUtil(d,m,y);
133         int[] mon_maxnum = Date.getDay().getMon_maxnum();
134         for (;n > 0;){
135             if (Date.getDay().getMonth().getYear().isLeapYear()){
136                 mon_maxnum[2] = 29;
137             }else{
138                 mon_maxnum[2] = 28;
139             }
140             if (Date.getDay().getValue() < mon_maxnum[Date.getDay().getMonth().getValue()]){//如果没有到每月的最后一天就天数加一
141                 Date.getDay().dayIncrement();
142                 n--;
143             }else{
144                 if (Date.getDay().getMonth().getValue() < 12){//否则月份小于12的话,月份加一,日变成1
145                     Date.getDay().getMonth().monthIncrement();
146                     Date.getDay().resetMin();
147                     n--;
148                 }else{//否则年份加一,月份为一月,日为一月的第一天
149                     Date.getDay().getMonth().resetMin();
150                     Date.getDay().resetMin();
151                     Date.getDay().getMonth().getYear().yearIncrement();
152                     n--;
153                 }
154             }
155         }
156         return Date;
157     }
158 
159     public DateUtil getPreviousNDays(int n){//求前n天
160         DateUtil Date = new DateUtil(d,m,y);
161         int[] mon_maxnum = Date.getDay().getMon_maxnum();
162         for (;n > 0;){
163             if (Date.getDay().getMonth().getYear().isLeapYear()){
164                 mon_maxnum[2] = 29;
165             }else{
166                 mon_maxnum[2] = 28;
167             }
168             if (Date.getDay().getValue() > 1) {//如果不是每个月的第一天那就日减一
169                 Date.getDay().dayReduction();
170                 n--;
171             }else{
172                 if (Date.getDay().getMonth().getValue() > 1){//否则月份大于1的话,月份减一,日为上个月的最大值
173                     Date.getDay().getMonth().monthReduction();
174                     Date.getDay().resetMax();
175                     n--;
176                 }else{//否则年份减一,月份为12月,日为12月的最大值
177                     Date.getDay().getMonth().resetMax();
178                     Date.getDay().resetMax();
179                     Date.getDay().getMonth().getYear().yearReduction();
180                     n--;
181                 }
182             }
183         }
184         return Date;
185     }
186 
187     public int getDaysofDates(DateUtil day){//求两天之差
188         int subtract = 0;
189         if (equalTwoDates(day)){//两天相等
190             return 0;
191         }else if (compareDates(day)){//传入的天数比较大
192             int i = this.y,j = this.m,k = this.d;//i,j,k分别表示年月日
193             DateUtil Date = new DateUtil(d,m,y);
194             int[] mon_maxnum = Date.getDay().getMon_maxnum();
195             for (;i <= day.y;){
196                 if (Date.getDay().getMonth().getYear().isLeapYear()){
197                     mon_maxnum[2] = 29;
198                 }else{
199                     mon_maxnum[2] = 28;
200                 }
201                 if (i == day.y){
202                     for (;j <= day.m;) {
203                         if (j == day.m) {//年份月份相等计算日期差
204                             if (Date.getDay().getMonth().getYear().isLeapYear()){
205                                 mon_maxnum[2] = 29;
206                             }else{
207                                 mon_maxnum[2] = 28;
208                             }
209                             subtract = subtract + day.getDay().getValue() - k;//运行结束之后跳出内循环
210                             break;
211                         } else {//否则直接加本月的天数
212                             subtract = subtract + mon_maxnum[j];
213                             j++;
214                         }
215                     }
216                     break;//跳出内循环之后跳出外循环
217                 }else{
218                     if (Date.getDay().getMonth().getYear().isLeapYear()){
219                         mon_maxnum[2] = 29;
220                     }else{
221                         mon_maxnum[2] = 28;
222                     }
223                     if (j < 12){
224                         subtract = subtract + mon_maxnum[j];
225                         j++;
226                     }else{
227                         subtract += 31;
228                         j = 1;
229                         i++;
230                         Date.getDay().getMonth().getYear().setValue(i);//调用setValue改变year
231                     }
232                 }
233             }
234         }else{//传入的天数比较小
235             int i = day.y,j = day.m,k = day.d;//i,j,k分别表示年月日
236             DateUtil Date = new DateUtil(day.d,day.m,day.y);
237             int[] mon_maxnum = Date.getDay().getMon_maxnum();
238             for (;i <= this.y;){
239                 if (Date.getDay().getMonth().getYear().isLeapYear()){
240                     mon_maxnum[2] = 29;
241                 }else{
242                     mon_maxnum[2] = 28;
243                 }
244                 if (i == this.y){
245                     for (;j <= this.m;){
246                         if (j == this.m){//年份月份相等计算日期差
247                             if (Date.getDay().getMonth().getYear().isLeapYear()){
248                                 mon_maxnum[2] = 29;
249                             }else{
250                                 mon_maxnum[2] = 28;
251                             }
252                             subtract = subtract + this.d - k;//运行结束之后跳出内循环
253                             break;
254                         }else{//否则直接加本月的天数
255                             subtract = subtract + mon_maxnum[j];
256                             j++;
257                         }
258                     }
259                     break;//跳出内循环之后跳出外循环
260                 }else{
261                     if (j < 12){
262                         subtract = subtract + mon_maxnum[j];
263                         j++;
264                     }else{
265                         subtract = subtract + 31;
266                         j = 1;
267                         i++;
268                         Date.getDay().getMonth().getYear().setValue(i);//调用setValue改变year
269                     }
270                 }
271             }
272         }
273         return subtract;
274     }
275 }
276 
277 class Day{
278     private int value;
279     private Month month;
280     private int[] mon_maxnum = {0,31,28,31,30,31,30,31,31,30,31,30,31};
281 
282     public Day(){
283 
284     }
285 
286     public Day(int yearValue,int monthValue,int dayValue){
287         this.value = dayValue;
288         this.month = new Month(monthValue,yearValue);
289     }
290 
291     public Month getMonth() {
292         return month;
293     }
294 
295     public void setMonth(Month month) {
296         this.month = month;
297     }
298 
299     public int getValue() {
300         return value;
301     }
302 
303     public void setValue(int value) {
304         this.value = value;
305     }
306 
307     public int[] getMon_maxnum() {
308         return mon_maxnum;
309     }
310 
311     public void setMon_maxnum(int[] mon_maxnum) {
312         this.mon_maxnum = mon_maxnum;
313     }
314 
315     public void resetMin(){
316         this.value = 1;
317     }
318 
319     public void resetMax(){
320         this.value = mon_maxnum[month.getValue()];
321     }
322 
323     public void dayIncrement(){//天数加一
324         this.value++;
325     }
326 
327     public void dayReduction(){//天数减一
328         this.value--;
329     }
330 }
331 
332 class Month{
333     private int value;
334     private Year year;
335 
336     public Month(){
337 
338     }
339 
340     public Month(int monthValue,int yearValue){
341         this.value = monthValue;
342         this.year = new Year(yearValue);
343     }
344 
345     public int getValue() {
346         return value;
347     }
348 
349     public void setValue(int value) {
350         this.value = value;
351     }
352 
353     public Year getYear() {
354         return year;
355     }
356 
357     public void setYear(Year year) {
358         this.year = year;
359     }
360 
361     public void resetMin(){
362         this.value = 1;
363     }
364 
365     public void resetMax(){
366         this.value = 12;
367     }
368 
369     public boolean validDate(){
370         if (value >= 1 && value <= 12){
371             return true;
372         }else{
373             return false;
374         }
375     }
376 
377     public void monthIncrement(){//月份加一
378         this.value++;
379     }
380 
381     public void monthReduction(){//月份减一
382         this.value--;
383     }
384 }
385 
386 class Year{
387     private int value;
388 
389     public Year(){
390 
391     }
392 
393     public Year(int yearValue){
394         this.value = yearValue;
395     }
396 
397     public int getValue() {
398         return value;
399     }
400 
401     public void setValue(int value) {
402         this.value = value;
403     }
404     public boolean isLeapYear(){//判断闰年
405         if ((value % 4 == 0 && value % 100 != 0) || (value % 400 == 0)) {
406             return true;
407         } else {
408             return false;
409         }
410     }
411 
412     public boolean validDate(){
413         if (value >= 1900 && value<= 2050){
414             return true;
415         }else{
416             return false;
417         }
418     }
419 
420     public void yearIncrement(){//年份加一
421         this.value++;
422     }
423 
424     public void yearReduction(){//年份减一
425         this.value--;
426     }
427 }

 

以下是本题的类图

通过代码看类与类之间的关系可能不太好看出来,但是通过类图关系就明了的许多,DateUtil与Day是聚合关系,Day与Month是聚合关系,Month与Year是聚合关系,如果DateUtil需要访问Month或Year之中的属性或者是方法的话只能通过Day去访问,在源码中这一点也是可以看到的。

日期问题面向对象设计(聚合二)

  本题的答题思路与上一题相同,但是类与类之间的关系变了,DateUtil与三个类一起聚合,意思就是DateUtil可以直接访问三个类的Value。由于本题大体的思路以及类与类之间的关系已经在上一篇博客和上一题说的差不多了,这就不过多赘述了,直接上源代码和类图。

 

  1 import java.util.*;
  2 public class Main {
  3     public static void main(String[] args){
  4         Scanner input = new Scanner(System.in);
  5         int year = 0;
  6         int month = 0;
  7         int day = 0;
  8 
  9         int choice = input.nextInt();
 10 
 11         if (choice == 1) { // test getNextNDays method
 12             int m = 0;
 13             year = Integer.parseInt(input.next());
 14             month = Integer.parseInt(input.next());
 15             day = Integer.parseInt(input.next());
 16 
 17             DateUtil date = new DateUtil(year, month, day);
 18 
 19             if (date.checkInputValidity()) {
 20                 System.out.println("Wrong Format");
 21                 System.exit(0);
 22             }
 23 
 24             m = input.nextInt();
 25 
 26             if (m < 0) {
 27                 System.out.println("Wrong Format");
 28                 System.exit(0);
 29             }
 30 
 31             System.out.print(date.getYear().getValue() + "-" + date.getMonth().getValue() + "-" + date.getDay().getValue() + " next " + m + " days is:");
 32             System.out.println(date.getNextNDays(m).showDate());
 33         }else if (choice == 2) { // test getPreviousNDays method
 34             int n = 0;
 35             year = Integer.parseInt(input.next());
 36             month = Integer.parseInt(input.next());
 37             day = Integer.parseInt(input.next());
 38 
 39             DateUtil date = new DateUtil(year, month, day);
 40 
 41             if (date.checkInputValidity()) {
 42                 System.out.println("Wrong Format");
 43                 System.exit(0);
 44             }
 45 
 46             n = input.nextInt();
 47 
 48             if (n < 0) {
 49                 System.out.println("Wrong Format");
 50                 System.exit(0);
 51             }
 52 
 53             System.out.print(
 54                     date.getYear().getValue() + "-" + date.getMonth().getValue() + "-" + date.getDay().getValue() + " previous " + n + " days is:");
 55             System.out.println(date.getPreviousNDays(n).showDate());
 56         }else if (choice == 3) {    //test getDaysofDates method
 57             year = Integer.parseInt(input.next());
 58             month = Integer.parseInt(input.next());
 59             day = Integer.parseInt(input.next());
 60 
 61             int anotherYear = Integer.parseInt(input.next());
 62             int anotherMonth = Integer.parseInt(input.next());
 63             int anotherDay = Integer.parseInt(input.next());
 64 
 65             DateUtil fromDate = new DateUtil(year, month, day);
 66             DateUtil toDate = new DateUtil(anotherYear, anotherMonth, anotherDay);
 67 
 68             if (!fromDate.checkInputValidity() && !toDate.checkInputValidity()) {
 69                 System.out.println("The days between " + fromDate.showDate() +
 70                         " and " + toDate.showDate() + " are:"
 71                         + fromDate.getDaysofDates(toDate));
 72             } else {
 73                 System.out.println("Wrong Format");
 74                 System.exit(0);
 75             }
 76         }
 77         else{
 78             System.out.println("Wrong Format");
 79             System.exit(0);
 80         }
 81     }
 82 }
 83 
 84 class DateUtil{
 85     private Day day;//使用带参数的构造方法
 86     private Month month;
 87     private Year year;
 88     private int[] mon_maxnum = {0,31,28,31,30,31,30,31,31,30,31,30,31};
 89 
 90     public DateUtil() {
 91         day = new Day();
 92         month = new Month();
 93         year = new Year();
 94     }
 95 
 96     public DateUtil(int y,int m,int d){
 97         day = new Day(d);
 98         month = new Month(m);
 99         year = new Year(y);
100     }
101 
102     public Day getDay() {
103         return day;
104     }
105 
106     public void setDay(Day day) {
107         this.day = day;
108     }
109 
110     public Month getMonth() {
111         return month;
112     }
113 
114     public void setMonth(Month month) {
115         this.month = month;
116     }
117 
118     public Year getYear() {
119         return year;
120     }
121 
122     public void setYear(Year year) {
123         this.year = year;
124     }
125 
126     public void setDayMax(){
127         this.day.setValue(mon_maxnum[month.getValue()]);
128     }
129 
130     public void setDayMin(){
131         this.day.setValue(1);
132     }
133 
134     public boolean checkInputValidity(){//判断输入是否有效
135         DateUtil Date = new DateUtil(this.day.getValue(),month.getValue(),year.getValue());
136         if (year.isLeapYear()){
137             this.mon_maxnum[2] = 29;
138         }else{
139             this.mon_maxnum[2] = 28;
140         }
141         if ((this.year.getValue() >= 1820 && this.year.getValue() <= 2020) && (this.month.getValue() >= 1 && this.month.getValue() <= 12)
142                 && (this.day.getValue() >= 1 && this.day.getValue() <= mon_maxnum[this.month.getValue()])){
143             return false;
144         }else{
145             return true;
146         }
147     }
148 
149     public boolean equalTwoDates(DateUtil date){//判断两天是否相等
150         if ((this.year.getValue() == date.getYear().getValue()) && (this.month.getValue() == date.getMonth().getValue())
151                 && (this.day.getValue() == date.getDay().getValue())) {
152             return true;
153         } else {
154             return false;
155         }
156     }
157 
158     public boolean compareDates(DateUtil date){//比较两天大小
159         if (this.year.getValue() < date.getYear().getValue()) {
160             return true;
161         } else if (this.month.getValue() < date.month.getValue() && date.year.getValue() == this.year.getValue()) {
162             return true;
163         } else if (this.day.getValue() < date.day.getValue() && this.month.getValue() == date.month.getValue() && date.year.getValue() == this.year.getValue()) {
164             return true;
165         } else {
166             return false;
167         }
168     }
169 
170     public String showDate(){//输出日期
171         return this.year.getValue()+"-"+this.month.getValue()+"-"+this.day.getValue();
172     }
173 
174     public DateUtil getPreviousNDays(int n){//求前n天
175         DateUtil Date = new DateUtil(this.year.getValue(),this.month.getValue(),this.day.getValue());
176         for (;n > 0;){
177             if (Date.getYear().isLeapYear()){//判断闰年
178                 Date.mon_maxnum[2] = 29;
179             }else{
180                 Date.mon_maxnum[2] = 28;
181             }
182             if (Date.getDay().getValue() > 1){//若天数大于一直接天数减一
183                 Date.getDay().dayReduction();
184                 n--;
185             }else{//否则看月份
186                 if (Date.getMonth().getValue() > 1){//月份大于一月份减一,天数为上个月的最大值
187                     Date.getMonth().monthReduction();
188                     Date.setDayMax();
189                     n--;
190                 }else{//否则年份减一,月份年份设为最大
191                     Date.getYear().yearReduction();
192                     Date.getMonth().resetMax();
193                     Date.setDayMax();
194                     n--;
195                 }
196             }
197         }
198         return Date;
199     }
200 
201     public DateUtil getNextNDays(int n){//求下n天
202         DateUtil Date = new DateUtil(this.year.getValue(),this.month.getValue(),this.day.getValue());
203         for (;n > 0;){
204             if (Date.getYear().isLeapYear()){//判断闰年
205                 this.mon_maxnum[2] = 29;
206             }else{
207                 this.mon_maxnum[2] = 28;
208             }
209             if (Date.getDay().getValue() < mon_maxnum[Date.getMonth().getValue()]){//天数小于本月的最大值直接天数加一
210                 Date.getDay().dayIncrement();
211                 n--;
212             }else {//否则看月份
213                 if (Date.getMonth().getValue() < 12){//月份小于12月份加一
214                     Date.getMonth().monthIncrement();
215                     Date.setDayMin();
216                     n--;
217                 }else{//否则年份加一
218                     Date.getMonth().resetMin();
219                     Date.setDayMin();
220                     Date.getYear().yearIncrement();
221                     n--;
222                 }
223             }
224         }
225         return Date;
226     }
227 
228     public int getDaysofDates(DateUtil date){//求两天之差
229         int subtract = 0;
230         if (equalTwoDates(date)){//两天相等
231             return 0;
232         }
233         if (compareDates(date)){//输入的天数比较大
234             int i = this.year.getValue(),j = this.month.getValue(),k = this.day.getValue();
235             for (;i <= date.getYear().getValue();){//判断闰年
236                 if (this.year.isLeapYear()){
237                     this.mon_maxnum[2] = 29;
238                 }else{
239                     this.mon_maxnum[2] = 28;
240                 }
241                 if (i == date.getYear().getValue()){//若年份相等
242                     for (;j <= date.getMonth().getValue();){
243                         if (j == date.getMonth().getValue()){//若月份相等则日相减
244                             subtract = subtract + date.getDay().getValue() - k;
245                             break;
246                         }else{//否则直接加本月的天数
247                             subtract = subtract + mon_maxnum[j];
248                             j++;
249                         }
250                     }
251                     break;
252                 }else{
253                     if (this.year.isLeapYear()){
254                         this.mon_maxnum[2] = 29;
255                     } else {
256                         this.mon_maxnum[2] = 28;
257                     }
258                     if (j < 12){//月份小于12直接加本月的天数
259                         subtract += mon_maxnum[j];
260                         j++;
261                     }else{
262                         subtract += 31;
263                         i++;
264                         j = 1;
265                         this.year.yearIncrement();//年份加一
266                     }
267                 }
268             }
269         }else{//输入的天数比较小
270             int i = date.getYear().getValue(),j = date.getMonth().getValue(),k = date.getDay().getValue();
271             for (;i <= this.year.getValue();) {
272                 if (date.getYear().isLeapYear()) {
273                     this.mon_maxnum[2] = 29;
274                 } else {
275                     this.mon_maxnum[2] = 28;
276                 }
277                 if (i == this.year.getValue()) {
278                     for (; j <= this.month.getValue(); ) {
279                         if (j == this.month.getValue()){
280                             subtract = subtract + this.day.getValue() - k;
281                             break;
282                         }else {
283                             subtract = subtract + mon_maxnum[j];
284                             j++;
285                         }
286                     }
287                     break;
288                 }else{
289                     if (date.getYear().isLeapYear()) {
290                         this.mon_maxnum[2] = 29;
291                     } else {
292                         this.mon_maxnum[2] = 28;
293                     }
294                     if (j < 12){
295                         subtract = subtract + mon_maxnum[j];
296                         j++;
297                     }else{
298                         subtract += 31;
299                         i++;
300                         j = 1;
301                         date.getYear().yearIncrement();//年份加一
302                     }
303                 }
304             }
305         }
306         return subtract;
307     }
308 }
309 
310 class Day{
311     private int value;
312 
313     public Day(){
314 
315     }
316 
317     public Day(int value) {
318         this.value = value;
319     }
320 
321     public int getValue() {
322         return value;
323     }
324 
325     public void setValue(int value) {
326         this.value = value;
327     }
328 
329     public void dayIncrement(){//天数加一
330         this.value++;
331     }//天数加一
332 
333     public void dayReduction(){//天数减一
334         this.value--;
335     }//天数减一
336 }
337 
338 class Month{
339     private int value;
340 
341     public Month(int value) {
342         this.value = value;
343     }
344 
345     public Month(){
346 
347     }
348 
349     public int getValue() {
350         return value;
351     }
352 
353     public void setValue(int value) {
354         this.value = value;
355     }
356 
357     public void resetMin(){
358         this.value = 1;
359     }//跨年月份设为1
360 
361     public void resetMax(){
362         this.value = 12;
363     }//跨年月份设为12
364 
365     public boolean validDate(){
366         if (value >= 1 && value <= 12){
367             return true;
368         }else{
369             return false;
370         }
371     }
372 
373     public void monthIncrement(){//月份加一
374         this.value++;
375     }//月份加一
376 
377     public void monthReduction(){//月份减一
378         this.value--;
379     }
380 }
381 
382 class Year{
383     private int value;
384 
385     public Year(){
386 
387     }
388 
389     public Year(int value) {
390         this.value = value;
391     }
392 
393     public int getValue() {
394         return value;
395     }
396 
397     public void setValue(int value) {
398         this.value = value;
399     }
400 
401     public boolean isLeapYear(){//判断闰年
402         if ((value % 4 == 0 && value % 100 != 0) || (value % 400 == 0)) {
403             return true;
404         } else {
405             return false;
406         }
407     }
408 
409     public boolean validDate(){
410         if (value >= 1820 && value<= 2020){
411             return true;
412         }else{
413             return false;
414         }
415     }
416 
417     public void yearIncrement(){//年份加一
418         this.value++;
419     }//年份加一
420 
421     public void yearReduction(){//年份减一
422         this.value--;
423     }//年份减一
424 }

 

 

 

菜单计价程序

  这里对菜单计价程序-3与菜单计价程序-4一同分析。

由于题目集4的一些题目需要学习其他的知识点,并且因为某些题目卡了我一段时间,所以我着手开始写菜单计价程序-3的时间有点晚,导致写这道题的时间也有点短。因为理解题目也需要一些时间,所以最终这道题也是无功而返。由于菜单计价程序-4是-3的加强版本,所以这里只对-4进行分析。

现附上我写的代码和类图:

  1 import java.util.*;
  2 
  3 import static javax.swing.UIManager.get;
  4 
  5 public class Main {
  6     public static void main(String[] args) {
  7         Scanner input = new Scanner(System.in);
  8         Menu menu = new Menu();//菜单
  9         Order[] order = new Order[100];//点餐记录
 10         String str = " ";//分割字符
 11         int tableTimes = 0;//记录有多少桌订单
 12         int[] reDeduplicationArray = new int[100],deplicationArray = new int[100],invalidDish = new int[100];//重复删除数组和删除数组和订单中出现菜单
 13         for (;!str.equals("end");){
 14             int deduplication = 0;//重复删除
 15             String[] splitedStr = {" "};
 16             if (tableTimes == 0) {
 17                 str = input.nextLine();
 18                 splitedStr = str.split(" ");
 19             }
 20             for (;splitedStr.length == 2 || splitedStr.length == 3;){//输入菜单
 21                 if (splitedStr[1].matches("\\d+")) {
 22                     if (splitedStr[1].matches("[1-9]|[1-9][1-9]|[1-2]\\d{2}|[1-2][1-9][1-9]")) {
 23                         if (splitedStr.length == 2) {
 24                             menu.addDish(splitedStr[0], Integer.parseInt(splitedStr[1]));
 25                         } else if (splitedStr[2].equals("T")) {
 26                             menu.addSpecialDish(splitedStr[0], Integer.parseInt(splitedStr[1]), splitedStr[2]);
 27                         }else{
 28                             System.out.println("wrong format");
 29                         }
 30                     }else{
 31                         System.out.println(splitedStr[0] + " price out of range " + splitedStr[1]);
 32                     }
 33                 }else{
 34                     System.out.println("wrong format");
 35                 }
 36                 str = input.nextLine();
 37                 splitedStr = str.split(" ");
 38             }
 39             if (str.equals("end")){
 40                 break;
 41             }
 42             order[tableTimes] = new Order();
 43             Table table = new Table();
 44             order[tableTimes].setTable(table);
 45             order[tableTimes].getTable().isValidity(str);
 46             str = input.nextLine();
 47             splitedStr = str.split(" ");
 48             if (splitedStr.length == 2){
 49                 invalidDish[tableTimes] = 1;
 50                 str = input.nextLine();
 51                 splitedStr = str.split(" ");
 52             }
 53             if (splitedStr.length > 4){
 54                 str = input.nextLine();
 55                 splitedStr = str.split(" ");
 56             }
 57             while(splitedStr.length == 4 && splitedStr[0].matches("\\d+")){//上面是记录桌号信息,下面是记录点菜信息
 58                 if (splitedStr[0].matches("[0]|[0]\\d+")){
 59                     System.out.println("wrong format");
 60                 }
 61                 order[tableTimes].addARecord(Integer.parseInt(splitedStr[0]),splitedStr[1],Integer.parseInt(splitedStr[2]),Integer.parseInt(splitedStr[3]));
 62                 str = input.nextLine();
 63                 splitedStr = str.split(" ");
 64             }
 65             if (splitedStr.length == 2){
 66                 deplicationArray[0] = Integer.parseInt(splitedStr[0]);
 67             }
 68             for (int i = 0,j = 1;splitedStr.length == 2;) {//记录删除信息
 69                 String strDelet;
 70                 strDelet = input.nextLine();
 71                 splitedStr = strDelet.split(" ");
 72                 if (splitedStr.length == 2) {
 73                     if (strDelet.equals(str)) {
 74                         deduplication = 1;
 75                         reDeduplicationArray[i] = Integer.parseInt(splitedStr[0]);
 76                         strDelet = input.nextLine();
 77                         splitedStr = strDelet.split(" ");
 78                         str = strDelet;
 79                         i++;
 80                         continue;
 81                     } else {
 82                         deplicationArray[j] = Integer.parseInt(splitedStr[0]);
 83                         j++;
 84                         str = strDelet;
 85                     }
 86                 }
 87                 str = strDelet;
 88             }
 89             tableTimes ++;
 90         }
 91         if (tableTimes != 0) {
 92             for (int i = 0; order[i] != null; i ++) {
 93                 WhichDay whichDay = new WhichDay(order[i]);
 94                 whichDay.setCompareTime();
 95                 whichDay.isValidDate();
 96                 if (order[i].getTable().isValidTable()){//是否输入的为table
 97                     if (order[i].getTable().isValidNumFormat()) {
 98                         if (order[i].getTable().isValidNum()) {//桌号是否在1-55之间
 99                             if (order[i].getTable().isValidDateFormat()) {
100                                 if (order[i].getTable().isValidDateData()) {
101                                     if (order[i].getTable().isDateData()) {
102                                         System.out.println("table " + order[i].getTable().getTableNum() + ": ");
103                                         if (invalidDish[tableTimes - 1] == 1) {
104                                             System.out.println("invalid dish");
105                                         }
106                                         for (int j = 0; order[i].getRecordsJ(j) != null; j++) {
107                                             if (menu.searchDish(order[i].getRecordsJ(j).getD().getName()) != null) {//判断菜单是否有该菜品
108                                                 boolean dishValid = true;//判断订单的某个菜品的份数或份额是否合法
109                                                 order[i].getRecordsJ(j).setD(menu.searchDish(order[i].getRecordsJ(j).getD().getName()));
110                                                 if (order[i].getRecordsJ(j).getPortion() > 3) {
111                                                     System.out.println(order[i].getRecordsJ(j).getOrderNum() + " portion out of range " + order[i].getRecordsJ(j).getPortion());
112                                                     dishValid = false;
113                                                 }
114                                                 if (order[i].getRecordsJ(j).getNum() > 15 && dishValid) {
115                                                     System.out.println(order[i].getRecordsJ(j).getOrderNum() + " num out of range " + order[i].getRecordsJ(j).getNum());
116                                                     dishValid = false;
117                                                 }
118                                                 if (dishValid) {//如果都合法,输出本菜品的信息
119                                                     System.out.println(order[i].getRecordsJ(j).getOrderNum() + " " + order[i].getRecordsJ(j).getD().getName() + " " + order[i].getRecordsJ(j).getPrice());
120                                                 } else {//否则将本菜品从记录中删除,在输出总价是不做计算
121                                                     order[i].delARecordByOrderNum(order[i].getRecordsJ(j).getOrderNum());
122                                                     j--;
123                                                 }
124                                             } else {
125                                                 System.out.println(order[i].getRecordsJ(j).getD().getName() + " does not exist");
126                                             }
127                                         }
128                                         for (int a = 0; reDeduplicationArray[a] != 0; a++) {
129                                             System.out.println("deduplication " + reDeduplicationArray[a]);
130                                         }
131                                         for (int a = 0; deplicationArray[a] != 0; a++) {
132                                             if (order[i].delARecordByOrderNum(deplicationArray[a]) == -1) {
133                                                 System.out.println("delete error");
134                                             }
135                                         }
136                                         if (!whichDay.getValidDate()) {//是否是在营业时间点菜
137                                             System.out.println("table " + order[i].getTable().getTableNum() + " out of opening hours");
138                                             break;
139                                         }
140                                         System.out.println("table " + order[i].getTable().getTableNum() + ": " + order[i].getTotalPrice() + " " + (int) (getDiscountedPrice(whichDay, menu) + 0.5));
141                                     }else{
142                                         System.out.println(order[i].getTable().getTableNum() + " date error");
143                                     }
144                                 }else {
145                                     System.out.println("not a valid time period");
146                                     }
147                             } else {
148                                 System.out.println("wrong format");
149                             }
150                         } else {
151                             System.out.println(order[i].getTable().getTableNum() + " table num out of range");
152                         }
153                     }else{
154                         System.out.println("wrong format");
155                     }
156                 }else{
157                     System.out.println("wrong format");
158                 }
159             }
160         }
161     }
162     public static double getDiscountedPrice(WhichDay whichDay, Menu menu){//获得折扣后的总价
163         int getDiscountedPrice = 0,totalSpecial = 0;
164         double discount = 1,total = 0;
165         if (whichDay.getWeek() == 1 || whichDay.getWeek() == 7){
166             getDiscountedPrice = whichDay.getOrder().getTotalPrice();
167             return getDiscountedPrice;
168         }else{
169             discount = whichDay.setDiscount();
170             for (int i = 0;whichDay.getOrder().getRecordsJ(i) != null;i ++){
171                 if (menu.searchDish(whichDay.getOrder().getRecordsJ(i).getD().getName()) != null) {
172                     if (menu.searchDish(whichDay.getOrder().getRecordsJ(i).getD().getName()).getIsSpecial().equals("F")) {
173                         getDiscountedPrice += whichDay.getOrder().getRecordsJ(i).getPrice();
174                     } else {
175                         totalSpecial += whichDay.getOrder().getRecordsJ(i).getPrice();
176                     }
177                 }
178             }
179             total = getDiscountedPrice * discount + totalSpecial * 0.7;
180             return total;
181         }
182     }
183 }
184 
185 class Dish{//菜品类
186     private String name;//菜品名称
187     private int unit_price;//单价
188     private String isSpecial = "F";
189     public Dish(){//无参数的构造方法
190 
191     }
192     public Dish(String name,int unit_price,String isSpecial) {
193         this.name = name;
194         this.unit_price = unit_price;
195         this.isSpecial = isSpecial;
196     }
197 
198     public Dish(String name,int unit_price) {
199         this.name = name;
200         this.unit_price = unit_price;
201     }
202 
203     public int getUnit_price() {
204         return unit_price;
205     }
206 
207     public String getIsSpecial() {
208         return isSpecial;
209     }
210 
211     public void setIsSpecial(String isSpecial) {
212         this.isSpecial = isSpecial;
213     }
214 
215     public int getPrice(int portion){////计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份)
216         return (int)(unit_price * (1 + (float)(portion - 1) / 2) + 0.5);
217     }
218     public void setName(String name){
219         this.name = name;
220     }
221     public String getName(){
222         return this.name;
223     }
224     public int setUnit_price(int unit_price){
225         return this.unit_price = unit_price;
226     }
227 }
228 
229 class Menu{//菜单类
230     private Dish[] dishes = new Dish[100];//菜品数组,保存菜品信息
231     private boolean isValidPrice = true;
232     int i;
233 
234     public boolean isValidPrice() {
235         return isValidPrice;
236     }
237 
238     public void setValidPrice(boolean validPrice) {
239         isValidPrice = validPrice;
240     }
241 
242     public Dish searchDish(String dishName){//根据菜名在菜谱中查找菜品信息,返回Dish对象
243         int len = 0;
244         for (int j = 0;dishes[j] != null;j ++){
245             len ++;
246         }
247         for (int j = 0;j < len;j++){
248             if (dishes[j].getName().equals(dishName)){
249                 return dishes[j];
250             }
251         }
252         return null;
253     }
254 
255     public Dish[] getDishes() {
256         return dishes;
257     }
258 
259     public void setDishes(Dish[] dishes) {
260         this.dishes = dishes;
261     }
262 
263     public Dish addDish(String dishName, int unit_price){//添加一道菜品信息
264         if (unit_price > 0 && unit_price < 300) {
265             if (i == 0) {//当为第一个菜品时
266                 dishes[0] = new Dish(dishName, unit_price);
267                 i++;
268                 return dishes[0];
269             } else {//当有了i样菜时,为第i+1个数组开辟新空间
270                 dishes[i] = new Dish(dishName, unit_price);
271                 i++;
272                 return dishes[i];
273             }
274         }
275         return null;
276     }
277 
278     public Dish addSpecialDish(String dishName, int unit_price,String isSpecial){//添加一道菜品信息
279         if (unit_price > 0 && unit_price < 300) {
280             if (i == 0) {//当为第一个菜品时
281                 dishes[0] = new Dish(dishName, unit_price, isSpecial);
282                 i++;
283                 return dishes[0];
284             } else {//当有了i样菜时,为第i+1个数组开辟新空间
285                 dishes[i] = new Dish(dishName, unit_price, isSpecial);
286                 i++;
287                 return dishes[i];
288             }
289         }
290         return null;
291     }
292 
293     public Menu(){//无参数的构造方法
294 
295     }
296     public Menu(Dish[] dishes){
297         this.dishes = dishes;
298     }
299 }
300 
301 class Record{//点菜记录类
302     private int orderNum;//序号
303     private Dish d = new Dish();//菜品
304     private int portion;//份额
305     private int num;//份数
306     private int price;
307     private boolean isValidPortion = true;//有效份额
308     private boolean isValidNum = true;//有效份数
309     public Record(){//无参数的构造方法
310 
311     }
312     public Record(int orderNum,Dish d,int portion,int num){
313         this.orderNum = orderNum;
314         this.d = d;
315         this.portion = portion;
316         this.num = num;
317     }
318 
319     public void setD(Dish d){
320         this.d = d;
321     }
322     public int getPrice(){//计价
323         return d.getPrice(portion)*num;
324     }
325 
326     public Dish getD(){
327 
328         return this.d;
329     }
330     public int getOrderNum(){
331         return this.orderNum;
332     }
333 
334     public void setOrderNum(int orderNum) {
335         this.orderNum = orderNum;
336     }
337 
338     public int getPortion() {
339         return portion;
340     }
341 
342     public void setPortion(int portion) {
343         this.portion = portion;
344     }
345 
346     public int getNum() {
347         return num;
348     }
349 
350     public void setNum(int num) {
351         this.num = num;
352     }
353 
354     public void setPrice(int price) {
355         this.price = price;
356     }
357 
358     public void isValidity(){
359         if (this.portion >= 1 && this.portion <= 3){
360             this.isValidPortion = true;
361         }else{
362             this.isValidPortion = false;
363         }
364         if (this.num >= 1 && this.num <= 15){
365             this.isValidNum = true;
366         }else{
367             this.isValidNum  = false;
368         }
369     }
370 
371 }
372 
373 class Order {//订单类
374     private Record[] records = new Record[100];
375     private Table table = new Table();
376     int i = 0;
377 
378     public Table getTable() {
379         return table;
380     }
381 
382     public void setTable(Table table) {
383         this.table = table;
384     }
385 
386     public int getTotalPrice(int dishesNum) {//获取本条记录的价格
387         int totalPrice = 0;
388         for (int j = 0; j < dishesNum; j++) {
389             totalPrice += records[j].getPrice();
390         }
391         return totalPrice;
392     }
393 
394     public Record addARecord(int orderNum, String dishName, int portion,int num) {//添加菜品信息
395         if (i == 0) {//当为第一条订单时
396             records[0] = new Record();
397             records[0] = new Record(orderNum, records[0].getD(), portion,num);
398             records[0].getD().setName(dishName);
399             i++;
400             return records[0];
401         } else {//超过一条,在第i+1个数组开辟新空间
402             records[i] = new Record();
403             records[i] = new Record(orderNum, records[i].getD(), portion,num);
404             records[i].getD().setName(dishName);
405             i++;
406             return records[i];
407         }
408     }
409 
410     public int delARecordByOrderNum(int orderNum) {//根据序号删除订单
411         int len = 0;
412         for (int i = 0;records[i] != null;i ++){
413             len ++;
414         }
415         for (int i = 0; i < records.length; i++) {
416             if (records[i].getOrderNum() == orderNum) {
417                 if (i < len - 1) {//如果删除的不是最后一个菜品
418                     records[i] = null;//删除第i项订单
419                     for (int j = i; j < records.length - 1; j++) {//将i后方的订单往前移一位
420                         records[j] = records[j + 1];
421                     }
422                 }else{
423                     records[i] = null;//删除第i项订单
424                 }
425                 return 1;
426             }
427         }
428         return -1;
429     }
430 
431     public boolean findRecordByNum(int orderNum) {//查找是否有某序号
432         for (int i = 0; i < records.length; i++) {
433             if (records[i].getOrderNum() == orderNum) {
434                 return true;
435             }
436         }
437         return false;
438     }
439 
440     public Record getRecordsJ(int j) {//获取第j+1道菜品订单的信息
441         return records[j];
442     }
443 
444     public void setRecords(Record[] records) {//获取本条记录的总价
445         this.records = records;
446     }
447 
448     public int getTotalPrice(){
449         int totalPrice = 0;
450         for (int i = 0;records[i] != null;i ++){
451             totalPrice += records[i].getPrice();
452         }
453         return totalPrice;
454     }
455 
456 }
457 
458 class OrderTime{//点菜时间类
459     private Calendar orderTime = Calendar.getInstance();//点菜时间
460 
461 
462     public Calendar getOrderTime() {
463         return orderTime;
464     }
465 
466     public void setOrderTime(int year,int month,int day,int hour,int minutes,int seconds) {//初始化点菜时间
467         this.orderTime.set(year,month,day,hour,minutes,seconds);
468     }
469 
470     public void setOrderTime(Calendar orderTime) {
471         this.orderTime = orderTime;
472     }
473 }
474 
475 class Table{
476     private OrderTime orderTime = new OrderTime();//点菜时间
477     private int tableNum;
478     private boolean isValidTable = true;//是否为table
479     private boolean isValidNum = true;//桌号是否在1-55
480     private boolean isValidNumFormat = true;//桌号是否为数字
481     private boolean dateData = true;//日期的数据是否合法
482     private boolean isValidDateData = true;//日期是否在范围内
483     private boolean isValidDateFormat = true;//日期格式是否合法
484 
485     public boolean isValidNumFormat() {
486         return isValidNumFormat;
487     }
488 
489     public boolean isValidDateData() {
490         return isValidDateData;
491     }
492 
493     public boolean isValidDateFormat() {
494         return isValidDateFormat;
495     }
496 
497     public boolean isDateData() {
498         return dateData;
499     }
500 
501     public OrderTime getOrderTime() {
502         return orderTime;
503     }
504 
505     public void setOrderTime(OrderTime orderTime) {
506         this.orderTime = orderTime;
507     }
508 
509     public Table(OrderTime orderTime) {
510         this.orderTime = orderTime;
511     }
512 
513     public Table() {
514     }
515 
516     public boolean isValidTable() {
517         return isValidTable;
518     }
519 
520     public boolean isValidNum() {
521         return isValidNum;
522     }
523 
524     public void isValidity(String str){//判断输入的订单桌号信息是否有效,有效则将桌号记录下来,无效则纪录无效
525         String[] splitedStr = str.split(" ");
526         String[] splitedDate = splitedStr[splitedStr.length - 2].split("/");
527         String[] splitedDay = splitedStr[splitedStr.length - 1].split("/");
528         if (Integer.parseInt(splitedDate[0]) >= 2022 && Integer.parseInt(splitedDate[0]) <= 2023){
529             isValidDateData = true;
530         }else{
531             isValidDateData = false;
532         }
533         if (splitedStr[0].equals("table")){
534             isValidTable = true;
535         }else{
536             isValidTable = false;
537         }
538         if (splitedDate[0].matches("\\d{4}") && splitedDate[1].matches("\\d{1,2}") && splitedDate[2].matches("\\d{1,2}") &&
539                 splitedDay[0].matches("\\d{1,2}") && splitedDay[1].matches("\\d{1,2}") && splitedDay[2].matches("\\d{1,2}")){
540             isValidDateFormat = true;
541         }else{
542             isValidDateFormat = false;
543         }
544         if (splitedStr[splitedStr.length - 3].matches("[1-9]\\d+")){
545             isValidNumFormat = true;
546             if (splitedStr[splitedStr.length - 3].matches("[1-9]|[1-4]\\d|5[0-5]")){
547                 isValidNum = true;
548             }else{
549                 isValidNum = false;
550             }
551             tableNum = Integer.parseInt(splitedStr[splitedStr.length-3]);
552             if (Integer.parseInt(splitedDate[1]) > 0 && Integer.parseInt(splitedDate[1]) <= 12) {//判断输入的年月是否合法
553                 Calendar calendar = Calendar.getInstance();
554                 calendar.set(Integer.parseInt(splitedDate[0]), Integer.parseInt(splitedDate[1]), Integer.parseInt(splitedDate[2]));
555                 if (Integer.parseInt(splitedDate[2]) > 0 && Integer.parseInt(splitedDate[2]) <= calendar.getActualMaximum(Calendar.DAY_OF_MONTH)) {//判断输入的日是否合法
556                     if (Integer.parseInt(splitedDay[0]) >= 0 && Integer.parseInt(splitedDay[0]) <= 23 && Integer.parseInt(splitedDay[1]) >= 0 &&
557                             Integer.parseInt(splitedDay[1]) <= 59 &&Integer.parseInt(splitedDay[2]) >= 0 && Integer.parseInt(splitedDay[2]) <= 59) {//判断输入的当天的时间是否合法
558                         orderTime.setOrderTime(Integer.parseInt(splitedDate[0]), Integer.parseInt(splitedDate[1]), Integer.parseInt(splitedDate[2])//若合法,则记录该时间
559                                 , Integer.parseInt(splitedDay[0]), Integer.parseInt(splitedDay[1]), Integer.parseInt(splitedDay[2]));
560                     }
561                 }else{
562                     dateData = false;
563                 }
564             }else{
565                 dateData = false;
566             }
567         }else{
568             isValidNumFormat = false;
569         }
570     }
571 
572     public int getTableNum() {
573         return tableNum;
574     }
575 
576     public void setTableNum(int tableNum) {
577         this.tableNum = tableNum;
578     }
579 }
580 
581 class WhichDay{
582     private Order order = new Order();
583     private boolean isValidDate = true;
584     private int week = order.getTable().getOrderTime().getOrderTime().get(Calendar.DAY_OF_WEEK);
585     Calendar[] compareTime = new Calendar[6];
586     public WhichDay() {
587     }
588 
589     public Order getOrder() {
590         return order;
591     }
592 
593     public void setOrder(Order order) {
594         this.order = order;
595     }
596 
597     public void setCompareTime() {//将营业时间的节点记录下来
598         for (int i = 0;i < 6;i++){
599             compareTime[i] = Calendar.getInstance();
600         }
601         compareTime[0].set(order.getTable().getOrderTime().getOrderTime().get(Calendar.YEAR),order.getTable().getOrderTime().getOrderTime().get(Calendar.MONTH)
602                 ,order.getTable().getOrderTime().getOrderTime().get(Calendar.DATE),10,30,0);
603         compareTime[1].set(order.getTable().getOrderTime().getOrderTime().get(Calendar.YEAR),order.getTable().getOrderTime().getOrderTime().get(Calendar.MONTH)
604                 ,order.getTable().getOrderTime().getOrderTime().get(Calendar.DATE),14,30,0);
605         compareTime[2].set(order.getTable().getOrderTime().getOrderTime().get(Calendar.YEAR),order.getTable().getOrderTime().getOrderTime().get(Calendar.MONTH)
606                 ,order.getTable().getOrderTime().getOrderTime().get(Calendar.DATE),17,30,0);
607         compareTime[3].set(order.getTable().getOrderTime().getOrderTime().get(Calendar.YEAR),order.getTable().getOrderTime().getOrderTime().get(Calendar.MONTH)
608                 ,order.getTable().getOrderTime().getOrderTime().get(Calendar.DATE),20,0,0);
609         compareTime[4].set(order.getTable().getOrderTime().getOrderTime().get(Calendar.YEAR),order.getTable().getOrderTime().getOrderTime().get(Calendar.MONTH)
610                 ,order.getTable().getOrderTime().getOrderTime().get(Calendar.DATE),9,30,0);
611         compareTime[5].set(order.getTable().getOrderTime().getOrderTime().get(Calendar.YEAR),order.getTable().getOrderTime().getOrderTime().get(Calendar.MONTH)
612                 ,order.getTable().getOrderTime().getOrderTime().get(Calendar.DATE),21,30,0);
613     }
614 
615     public WhichDay(Order order) {
616         this.order = order;
617     }
618 
619     public int getWeek() {
620         return week;
621     }
622 
623     public void isValidDate(){//还有输入格式错误的问题没有解决
624         if (week >= 2 && week <= 6){
625             if (((((order.getTable().getOrderTime().getOrderTime()).getTimeInMillis() >= compareTime[0].getTimeInMillis())) &&
626                     (order.getTable().getOrderTime().getOrderTime()).getTimeInMillis() <= (compareTime[1].getTimeInMillis())) ||
627                     (((order.getTable().getOrderTime().getOrderTime()).getTimeInMillis() >= (compareTime[2]).getTimeInMillis()) &&
628                             ((order.getTable().getOrderTime().getOrderTime()).getTimeInMillis() <= (compareTime[3]).getTimeInMillis()))){
629                 isValidDate = true;
630             }else if((((order.getTable().getOrderTime().getOrderTime()).getTimeInMillis() >= (compareTime[0].getTimeInMillis())) &&
631                     (order.getTable().getOrderTime().getOrderTime()).getTimeInMillis() <= (compareTime[1].getTimeInMillis())) ||
632                     (((order.getTable().getOrderTime().getOrderTime()).getTimeInMillis() >= (compareTime[2].getTimeInMillis())) &&
633                             ((order.getTable().getOrderTime().getOrderTime()).getTimeInMillis() <= (compareTime[3].getTimeInMillis())))){
634                 isValidDate = true;
635             }else{
636                 isValidDate = false;
637             }
638         }else{
639             if ((((order.getTable().getOrderTime().getOrderTime()).getTimeInMillis() >= (compareTime[4].getTimeInMillis())) &&
640                     ((order.getTable().getOrderTime().getOrderTime()).getTimeInMillis() <= (compareTime[5].getTimeInMillis())))){
641                 isValidDate = true;
642             }else if ((((order.getTable().getOrderTime().getOrderTime()).getTimeInMillis() >= (compareTime[4].getTimeInMillis())) &&
643                     ((order.getTable().getOrderTime().getOrderTime()).getTimeInMillis() <= (compareTime[5].getTimeInMillis())))){
644                 isValidDate = true;
645             }else{
646                 isValidDate = false;
647             }
648         }
649     }
650 
651     public double setDiscount(){
652         double discount;
653         if (((order.getTable().getOrderTime().getOrderTime()).compareTo(compareTime[0]) == 1) &&
654                 (order.getTable().getOrderTime().getOrderTime()).compareTo(compareTime[1]) == -1){
655             discount = 0.6;
656         }else{
657             discount = 0.8;
658         }
659         return discount;
660     }
661 
662     public void setValidDate(boolean validDate) {
663         isValidDate = validDate;
664     }
665 
666     public boolean getValidDate(){
667         return isValidDate;
668     }
669 
670 }

我处理输入的数据的方法是先将字符分割,存入字符串数组,然后看字符串数组的长度,因为菜单首先输入的,并且长度只可能为2或3,所以首席记录菜单,并且只记录一次菜单,如果后面还有菜单输入的话,则会直接记录无效。后面一行输入的是订单桌号的信息,由于桌号的长度会与点菜记录的长度冲突,所以我选择将这条信息传入Table中,让里面的isValidity方法进行处理。

 

 1 public void isValidity(String str){//判断输入的订单桌号信息是否有效,有效则将桌号记录下来,无效则纪录无效
 2         String[] splitedStr = str.split(" ");
 3         String[] splitedDate = splitedStr[splitedStr.length - 2].split("/");
 4         String[] splitedDay = splitedStr[splitedStr.length - 1].split("/");
 5         if (Integer.parseInt(splitedDate[0]) >= 2022 && Integer.parseInt(splitedDate[0]) <= 2023){
 6             isValidDateData = true;
 7         }else{
 8             isValidDateData = false;
 9         }
10         if (splitedStr[0].equals("table")){
11             isValidTable = true;
12         }else{
13             isValidTable = false;
14         }
15         if (splitedDate[0].matches("\\d{4}") && splitedDate[1].matches("\\d{1,2}") && splitedDate[2].matches("\\d{1,2}") &&
16                 splitedDay[0].matches("\\d{1,2}") && splitedDay[1].matches("\\d{1,2}") && splitedDay[2].matches("\\d{1,2}")){
17             isValidDateFormat = true;
18         }else{
19             isValidDateFormat = false;
20         }
21         if (splitedStr[splitedStr.length - 3].matches("[1-9]\\d+")){
22             isValidNumFormat = true;
23             if (splitedStr[splitedStr.length - 3].matches("[1-9]|[1-4]\\d|5[0-5]")){
24                 isValidNum = true;
25             }else{
26                 isValidNum = false;
27             }
28             tableNum = Integer.parseInt(splitedStr[splitedStr.length-3]);
29             if (Integer.parseInt(splitedDate[1]) > 0 && Integer.parseInt(splitedDate[1]) <= 12) {//判断输入的年月是否合法
30                 Calendar calendar = Calendar.getInstance();
31                 calendar.set(Integer.parseInt(splitedDate[0]), Integer.parseInt(splitedDate[1]), Integer.parseInt(splitedDate[2]));
32                 if (Integer.parseInt(splitedDate[2]) > 0 && Integer.parseInt(splitedDate[2]) <= calendar.getActualMaximum(Calendar.DAY_OF_MONTH)) {//判断输入的日是否合法
33                     if (Integer.parseInt(splitedDay[0]) >= 0 && Integer.parseInt(splitedDay[0]) <= 23 && Integer.parseInt(splitedDay[1]) >= 0 &&
34                             Integer.parseInt(splitedDay[1]) <= 59 &&Integer.parseInt(splitedDay[2]) >= 0 && Integer.parseInt(splitedDay[2]) <= 59) {//判断输入的当天的时间是否合法
35                         orderTime.setOrderTime(Integer.parseInt(splitedDate[0]), Integer.parseInt(splitedDate[1]), Integer.parseInt(splitedDate[2])//若合法,则记录该时间
36                                 , Integer.parseInt(splitedDay[0]), Integer.parseInt(splitedDay[1]), Integer.parseInt(splitedDay[2]));
37                     }
38                 }else{
39                     dateData = false;
40                 }
41             }else{
42                 dateData = false;
43             }
44         }else{
45             isValidNumFormat = false;
46         }
47     }

 

在这个方法中,我首先对字符进行了分割,并且判断分割之后的年份是否在题目要求的范围之内,如果不在的话,则会使用isValidDateData记录下来(这里有个要注意的地方,因为table可能会变成ta ble所以字符串数组的长度不确定,因此需要从数组的尾部元素倒退来访问数组里面的元素,倒数第一个是日,倒数第二个是年,倒数第三个是桌号),随后判断第一个字符串是否为table,如果不是table的话,则会用isValidTable记录下来。随后是对日期格式输入的合法性进行判断,这里我使用了简单的正则表达式进行判断,如果不符合格式的话,则会像上面一样记录下来。然后是对桌号的判断,首先需要需要用正则判断桌号是不是非零开头的数字,如果不是的话则会记录下来,随后同样的再用正则对桌号的大小进行判断。最后对具体的日期数据进行判断,如果合法的话,则会记录该时间,否则记录数据非法。

随后是处理订单,这是处理订单的代码:

 

 1         while(splitedStr.length == 4 && splitedStr[0].matches("\\d+")){//上面是记录桌号信息,下面是记录点菜信息
 2                 if (splitedStr[0].matches("[0]|[0]\\d+")){
 3                     System.out.println("wrong format");
 4                 }
 5                 order[tableTimes].addARecord(Integer.parseInt(splitedStr[0]),splitedStr[1],Integer.parseInt(splitedStr[2]),Integer.parseInt(splitedStr[3]));
 6                 str = input.nextLine();
 7                 splitedStr = str.split(" ");
 8             }

 

首先要考虑的就是点菜序号的最高位不能是0开头,否则直接输出wrong format,随后再录入输入的信息。 

后面是处理订单的删除信息:

 1             if (splitedStr.length == 2){
 2                 deplicationArray[0] = Integer.parseInt(splitedStr[0]);
 3             }
 4             for (int i = 0,j = 1;splitedStr.length == 2;) {//记录删除信息
 5                 String strDelet;
 6                 strDelet = input.nextLine();
 7                 splitedStr = strDelet.split(" ");
 8                 if (splitedStr.length == 2) {
 9                     if (strDelet.equals(str)) {
10                         deduplication = 1;
11                         reDeduplicationArray[i] = Integer.parseInt(splitedStr[0]);
12                         strDelet = input.nextLine();
13                         splitedStr = strDelet.split(" ");
14                         str = strDelet;
15                         i++;
16                         continue;
17                     } else {
18                         deplicationArray[j] = Integer.parseInt(splitedStr[0]);
19                         j++;
20                         str = strDelet;
21                     }
22                 }
23                 str = strDelet;
24             }    

这里我是用一个数组保存了删除的菜品的菜序号,在循环的外面先保存第一个删除的信息,因为第一个删除不可能会存在重复,随后再进入循环,循环内部的if语句就是如果有重复的删除记录的话,就会记录下来,否则就将删除的菜序号记录下来,但是由于我大部分的字符串操作都是由str完成,所以语句的最后需要把strDelet赋给str。

最后就是我的代码的输出部分:

 1         if (tableTimes != 0) {
 2             for (int i = 0; order[i] != null; i ++) {
 3                 WhichDay whichDay = new WhichDay(order[i]);
 4                 whichDay.setCompareTime();
 5                 whichDay.isValidDate();
 6                 if (order[i].getTable().isValidTable()){//是否输入的为table
 7                     if (order[i].getTable().isValidNumFormat()) {
 8                         if (order[i].getTable().isValidNum()) {//桌号是否在1-55之间
 9                             if (order[i].getTable().isValidDateFormat()) {
10                                 if (order[i].getTable().isValidDateData()) {
11                                     if (order[i].getTable().isDateData()) {
12                                         System.out.println("table " + order[i].getTable().getTableNum() + ": ");
13                                         if (invalidDish[tableTimes - 1] == 1) {
14                                             System.out.println("invalid dish");
15                                         }
16                                         for (int j = 0; order[i].getRecordsJ(j) != null; j++) {
17                                             if (menu.searchDish(order[i].getRecordsJ(j).getD().getName()) != null) {//判断菜单是否有该菜品
18                                                 boolean dishValid = true;//判断订单的某个菜品的份数或份额是否合法
19                                                 order[i].getRecordsJ(j).setD(menu.searchDish(order[i].getRecordsJ(j).getD().getName()));
20                                                 if (order[i].getRecordsJ(j).getPortion() > 3) {
21                                                     System.out.println(order[i].getRecordsJ(j).getOrderNum() + " portion out of range " + order[i].getRecordsJ(j).getPortion());
22                                                     dishValid = false;
23                                                 }
24                                                 if (order[i].getRecordsJ(j).getNum() > 15 && dishValid) {
25                                                     System.out.println(order[i].getRecordsJ(j).getOrderNum() + " num out of range " + order[i].getRecordsJ(j).getNum());
26                                                     dishValid = false;
27                                                 }
28                                                 if (dishValid) {//如果都合法,输出本菜品的信息
29                                                     System.out.println(order[i].getRecordsJ(j).getOrderNum() + " " + order[i].getRecordsJ(j).getD().getName() + " " + order[i].getRecordsJ(j).getPrice());
30                                                 } else {//否则将本菜品从记录中删除,在输出总价是不做计算
31                                                     order[i].delARecordByOrderNum(order[i].getRecordsJ(j).getOrderNum());
32                                                     j--;
33                                                 }
34                                             } else {
35                                                 System.out.println(order[i].getRecordsJ(j).getD().getName() + " does not exist");
36                                             }
37                                         }
38                                         for (int a = 0; reDeduplicationArray[a] != 0; a++) {
39                                             System.out.println("deduplication " + reDeduplicationArray[a]);
40                                         }
41                                         for (int a = 0; deplicationArray[a] != 0; a++) {
42                                             if (order[i].delARecordByOrderNum(deplicationArray[a]) == -1) {
43                                                 System.out.println("delete error");
44                                             }
45                                         }
46                                         if (!whichDay.getValidDate()) {//是否是在营业时间点菜
47                                             System.out.println("table " + order[i].getTable().getTableNum() + " out of opening hours");
48                                             break;
49                                         }
50                                         System.out.println("table " + order[i].getTable().getTableNum() + ": " + order[i].getTotalPrice() + " " + (int) (getDiscountedPrice(whichDay, menu) + 0.5));
51                                     }else{
52                                         System.out.println(order[i].getTable().getTableNum() + " date error");
53                                     }
54                                 }else {
55                                     System.out.println("not a valid time period");
56                                     }
57                             } else {
58                                 System.out.println("wrong format");
59                             }
60                         } else {
61                             System.out.println(order[i].getTable().getTableNum() + " table num out of range");
62                         }
63                     }else{
64                         System.out.println("wrong format");
65                     }
66                 }else{
67                     System.out.println("wrong format");
68                 }
69             }
70         }

 

因为我设计了一个WhichDay类专门来记录每一桌订单的时间,并且来判断时间是否在营业时间以及是否在打折的时间以便输出异常的信息和输出最后的总价,所以我先把order的信息传入了WhichDay。首先是对前面的非法格式进行判断,如果存在非法格式,则输出wrong format,否则就输出订单的信息。订单的信息先输出table以及对应的桌号,后面再输入点菜的信息,在输出点菜信息之前还要对它做出判断,首先是要判断点的菜在菜单中是否存在,如果不存在,则输出这道菜不存在的信息,否则再对菜的份数和份额进行验证,如果二者都超出限制,则只输出份数的异常,并且删除此条点菜信息(在删除点菜信息的同时需要对循环变量减一,因为删除点菜信息,则数组的长度会发生改变,后面的点菜信息都会往前移一位,因此循环变量也要相应的往前移一位)。在这些都判断无误之后则输出对应的点菜信息。

以下是本题的类图:

3、踩坑心得

  关于踩坑,这三次作业我踩的最大的一个坑就是使用printf方法导致题目集四的第三题超时还一直找不到问题这个坑了,但是因为上面已经讲到了这个,所以这边不再过多赘述了。第二个坑就是题目集四的第六题,也是输出的问题,因为测试样例的秒是有两位小数,所以输出时也是有两位小时,所以我就误以为输出秒的时候需要保留两位小数,因此导致这道题总是过不了。最后还是在同学的提示下才发现了这个问题。

关于我踩的最后一个坑,可以说踩,也可以说刚好避过了这个坑,那就是刚刚开始写正则表达式训练题的时候,因为学习通上的慕课罗老师讲的都是用if与去匹配字符串,所以我刚刚开始写代码的时候也是用的这个方法写后面提交了一次代码,发现只过了几个测试点

后面就开始改代码,发现越来越不对劲,为什么会这么麻烦???我之前好像在书上看到过有的地方说到了正则表达式,说的是matches方法,所以发现不对劲之后又去看了一下matches方法的用法,好家伙,原来可以直接用正则表达式去匹配字符串,那就好办了啊!直接用matches方法就行了。

4、改进建议

  我认为题目集需要改进的地方就是一个,那就是题目代码行数比较多,测试点也比较多的时候,应该多给出几个测试样例以作参考,本次题目集六的菜单系统中的七个样例我已经有六个与输出样例答案一样了,但是还是有很多的测试点过不了。虽然pta的测试点已经给出了相应的提示,但是没有测试样例作参考,修改代码还是一件比较难的事情,毕竟这次的菜单系统有时候要输出很多的东西,要考虑的情况也很多,有时候可能只是输出顺序出了错误,可是没有测试样例作参考的话,是很难改出错误的。而且我认为在这个地方耗费太多时间是没有很大的意义的。

5、总结

  关于这三次题目集,真的是感慨万千,切实的感受到了java这门课程的难度,三次题目集有两次都没有满分,甚至第六次还是一个不及格,在以前的pta的作业,我一直都是以为只需要随便写一下,花点时间就一定可以满分的,可是到现在不一样了啊!就算我花了时间,认真的去写了,可能最后的成绩也不是很理想。

  关于pta的作业,我想写好吗?我真的很想写好啊!发布作业的时间是周末,但是由于周末我事情比较多,所以题目是拖到了周一才开始动手写的,但是后面几天,我几乎是一有时间就开始写代码。虽然没有二十个小时那么多吧,但是十个小时以上是最少的,但是最后的结果好像却不太理想,不过这点我自己也需要检讨一下我自己,为什么不能腾出更多是的时间来写代码?为什么写了十多个小时的代码交上去却是那样的一个结果?如果我和更多优秀的同学交换意见是不是结果会更好一点?

题外话(发牢骚)

  最近事情真的好多,而且课程的难度都上来了,java、高数、线代、离散、英语四级(上次没抢到名额,绝对不是我考了没过)以及其他的一些事情都是需要花时间的,感觉时间怎么用都不够用。记得刚开学那会,我写完作业周末居然还有多余的时间打游戏!现在的这几周我都没打游戏了,时间还是不够用,感觉很多作业写的都很水,感觉是我自己没有规划好时间。不知道为什么要写这段话,就当是发发牢骚吧T_T。

 

 

 

 

 

 

 

 

 

 

 

标签:总结性,题目,int,Blog2,System,splitedStr,public,order,out
From: https://www.cnblogs.com/WWWjl/p/17351260.html

相关文章

  • 3、题目:Feedback in concept development: Comparing design disciplines
    期刊信息(1)作者:Yilmaz,Seda.(2)期刊:DesignStudies,2016,45:137-158(3)DOI:10.1016/j.destud.2015.12.008(4)ISSN:0142-694X(5)IF:3.853(Q2)研究背景设计反馈是促进学生设计进步的必要教学工具,但很少有研究关注教师的反馈是什么样子的,特别是在跨设计学科方面研......
  • 4、题目:Creativity in Electrical Engineering Degree Programs: Where Is the Conten
    期刊信息(1)作者:Adams,Scott(2)期刊:IEEETransactionsonEducation,2019/11,62-4:288-296(3)DOI:10.1109/TE.2019.2912834(4)ISSN:0018-9359(5)IF:2.74(Q2)研究背景先前的研究表明,工程教学大纲中包含创造力培养,课堂活动通常受到限制。学生可能认为教育工作者不重视......
  • 对Java课程PTA4-6题目集的反思与总结
     前言:三次题目集一共涵盖了以下知识点:面向对象编程的封装性,List-Arrays方法的使用,强制类型转换的方法,字符串的处理,字符串截断方法split的使用,对象数组的建立以及使用,Java源码自带的多种日期类方法的使用,各种正则表达式及其运用,运用聚合的方法自行写日期类,综合运用现学的所......
  • JavaBlog2
    一、前言本次博客文章主要是关于java课程第二阶段关于PTA题目集、超星作业以及期中考试的总结。相较于第一阶段的作业总结而言此次作业更加针对于总结在面向对象过程中的三大技术特性,即封装性、继承性和多态性,以及相关一些面向对象设计过程中的一些基本原则的理解和分析此阶段作......
  • 题目集4-6总结
    一,前言本次的题目相较于上次的题目,题量有所下降,但整体上难度上升了,已经不再是让我们熟悉基础语法的题目了,更倾向于增强我们的编程能力,比如题目集4的7-1,比同一个题目集的其他题要难,而且代码量也要大,相较于其他题目,更能给人一种不想做的感觉。题目集4中的题目都可以通过使用一些方......
  • 题目 3158: 蓝桥杯2023年第十四届省赛真题-三国游戏(贪心)
    题目描述小蓝正在玩一款游戏。游戏中魏蜀吴三个国家各自拥有一定数量的士兵X,Y,Z(一开始可以认为都为0)。游戏有n个可能会发生的事件,每个事件之间相互独立且最多只会发生一次,当第i个事件发生时会分别让X,Y,Z增加Ai,Bi,Ci。当游戏结束时(所有事件的发生与否已......
  • 华为OD机试真题2023 精简版,如果距离机考时间不多了,就看这个吧(50道100分题目)
    关于华为od题库的说明2023年参加华为OD机试,你收到的短信邀请链接中提及的应该是 2022Q4 或者 2023Q1 都是A卷。只要是这样的试卷标题,那表示你使用的就是华为OD的新题库了。华为机试有三道题,前2道100分,第3道200分,总分是400分。随着时间的积累,题库内容越来越大,很多朋友现......
  • JAVA面向对象程序设计_PTA题目集04-06总结分析
    前言:JAVA_BLOG_PTA题目集4-6_总结分析 题目集四:知识点:大体如预备知识,即:通过查询JavaAPI文档,了解Scanner类中nextLine()等方法、String类中split()等方法、Integer类中parseInt()等方法的用法,了解LocalDate类中of()、isAfter()、isBefore()、until()等方法的使用规则,了解Chro......
  • 题目集4~6的总结性Blog
    目录 1.前言2.设计与分析3.踩坑心得4.改进建议5.总结 1.前言题目集4: (训练自我学习能力,例如treeset与hashset用法,了解一些类中的方法) 菜单计价程序-3有重复的数据有重复的数据 单词统计与排序 面向对象编程(封装性) GPS测绘中度分秒转换 判断两个日期......
  • pta第四次到第六次题目集
    (1)前言pta第四次作业的7-2到7-4主要学会了运用容器类——LinkedHashSet,对重复的数据进行检查,刚入手有点不熟练。7-7通过查询JavaAPI文档,了解了Scanner类中nextLine()等方法、String类中split()等方法、Integer类中parseInt()等方法的用法,了解LocalDate类中of()、isAfter()、isBef......