一、前言
第二次在博客園上發布面向物件程式設計題目集的總結博客,經過幾周的學習,面向物件的理念更加深入,雖然已經學了些面向物件程式設計,學好這部分內容還是有較大難度,
- 關于知識點
本次的題目集所體現的知識點已經不僅限于Java的語法知識,還需要考慮設計問題,不能看到題目就開始進行代碼撰寫,需要考慮類和類之間的關系,題目的代碼量也較于前幾次提升了不少,題目集四主要還是語法的鞏固,學會去使用一些新的知識,例如題目集中的第七題中使用一些新的類來解決問題,題目集五前四題是關于正則運算式的知識點,后兩題是日期問題,需要用到類的聚合關系,題目集六主要涉及類的繼承與多型的內容,后面的有些題目未給出類圖,需要自行設計考慮類之間的關系,
- 關于題量
題量比較適中,平均每次題目集都是5-6題,除了有些題目不大好設計比較花時間,
- 關于難度
由于涉及了面向物件設計原理和法則(例如遵從迪米特法則、開閉原則等),難度較于前幾次自然有所增加,但是在部分題目有類圖的情況下,難度適中,除了一些題目敘述較長未能進行較好的設計,
二、設計與分析
- 題目集三7-1 選單計價程式-3
設計點菜計價程式,根據輸入的資訊,計算并輸出總價格,
輸入內容按先后順序包括兩部分:選單、訂單,最后以"end"結束,
選單由一潭訓多條菜品記錄組成,每條記錄一行
每條菜品記錄包含:菜名、基礎價格 兩個資訊,
訂單分:桌號標識、點菜記錄和洗掉資訊、代點菜資訊,每一類資訊都可包含一潭訓多條記錄,每條記錄一行或多行,
桌號標識獨占一行,包含兩個資訊:桌號、時間,
桌號以下的所有記錄都是本桌的記錄,直至下一個桌號標識,
點菜記錄包含:序號、菜名、份額、份數,份額可選項包括:1、2、3,分別代表小、中、大份,
不同份額菜價的計算方法:小份菜的價格=菜品的基礎價格,中份菜的價格=菜品的基礎價格1.5,小份菜的價格=菜品的基礎價格2,如果計算出現小數,按四舍五入的規則進行處理,
洗掉記錄格式:序號 delete
標識洗掉對應序號的那條點菜記錄,
如果序號不對,輸出"delete error"
代點菜資訊包含:桌號 序號 菜品名稱 份額 分數
代點菜是當前桌為另外一桌點菜,資訊中的桌號是另一桌的桌號,帶點菜的價格計算在當前這一桌,
程式最后按輸入的先后順序依次輸出每一桌的總價(注意:由于有代點菜的功能,總價不一定等于當前桌上的菜的價格之和),
每桌的總價等于那一桌所有菜的價格之和乘以折扣,如存在小數,按四舍五入規則計算,保留整數,
折扣的計算方法(注:以下時間段均按閉區間計算):
周一至周五營業時間與折扣:晚上(17:00-20:30)8折,周一至周五中午(10:30--14:30)6折,其余時間不營業,
周末全價,營業時間:9:30-21:30
如果下單時間不在營業范圍內,輸出"table " + t.tableNum + " out of opening hours"
參考以下類的模板進行設計:菜品類:對應菜譜上一道菜的資訊,
Dish {
String name;//菜品名稱
int unit_price; //單價
int getPrice(int portion)//計算菜品價格的方法,輸入引數是點菜的份額(輸入資料只能是1/2/3,代表小/中/大份) }
菜譜類:對應菜譜,包含飯店提供的所有菜的資訊,
Menu {
Dish\[\] dishs ;//菜品陣列,保存所有菜品資訊
Dish searthDish(String dishName)//根據菜名在菜譜中查找菜品資訊,回傳Dish物件,
Dish addDish(String dishName,int unit_price)//添加一道菜品資訊
}
點菜記錄類:保存訂單上的一道菜品記錄
Record {
int orderNum;//序號\\
Dish d;//菜品\\
int portion;//份額(1/2/3代表小/中/大份)\\
int getPrice()//計價,計算本條記錄的價格\\
}
訂單類:保存用戶點的所有菜的資訊,
Order {
Record\[\] records;//保存訂單上每一道的記錄
int getTotalPrice()//計算訂單的總價
Record addARecord(int orderNum,String dishName,int portion,int num)//添加一條菜品資訊到訂單中,
delARecordByOrderNum(int orderNum)//根據序號洗掉一條記錄
findRecordByNum(int orderNum)//根據序號查找一條記錄
}
### 輸入格式:
桌號標識格式:table + 序號 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 時間(24小時制格式: HH/MM/SS)
菜品記錄格式:
菜名+英文空格+基礎價格
如果有多條相同的菜名的記錄,菜品的基礎價格以最后一條記錄為準,
點菜記錄格式:序號+英文空格+菜名+英文空格+份額+英文空格+份數注:份額可輸入(1/2/3), 1代表小份,2代表中份,3代表大份,
洗掉記錄格式:序號 +英文空格+delete
代點菜資訊包含:桌號+英文空格+序號+英文空格+菜品名稱+英文空格+份額+英文空格+分數
最后一條記錄以“end”結束,
### 輸出格式:
按輸入順序輸出每一桌的訂單記錄處理資訊,包括:
1、桌號,格式:table+英文空格+桌號+”:”
2、按順序輸出當前這一桌每條訂單記錄的處理資訊,
每條點菜記錄輸出:序號+英文空格+菜名+英文空格+價格,其中的價格等于對應記錄的菜品\*份數,序號是之前輸入的訂單記錄的序號,如果訂單中包含不能識別的菜名,則輸出“\*\* does not exist”,\*\*是不能識別的菜名
如果洗掉記錄的序號不存在,則輸出“delete error”
最后按輸入順序一次輸出每一桌所有菜品的總價(整數數值)格式:table+英文空格+桌號+“:”+英文空格+當前桌的總價
本次題目不考慮其他錯誤情況,如:桌號、選單訂單順序顛倒、不符合格式的輸入、序號重復等,在本系列的后續作業中會做要求,
輸入格式:
桌號標識格式:table + 序號 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 時間(24小時制格式: HH/MM/SS)
菜品記錄格式:
菜名+英文空格+基礎價格
如果有多條相同的菜名的記錄,菜品的基礎價格以最后一條記錄為準,
點菜記錄格式:序號+英文空格+菜名+英文空格+份額+英文空格+份數注:份額可輸入(1/2/3), 1代表小份,2代表中份,3代表大份,
洗掉記錄格式:序號 +英文空格+delete
代點菜資訊包含:桌號+英文空格+序號+英文空格+菜品名稱+英文空格+份額+英文空格+分數
最后一條記錄以“end”結束,
輸出格式:
按輸入順序輸出每一桌的訂單記錄處理資訊,包括:
1、桌號,格式:table+英文空格+桌號+“:”
2、按順序輸出當前這一桌每條訂單記錄的處理資訊,
每條點菜記錄輸出:序號+英文空格+菜名+英文空格+價格,其中的價格等于對應記錄的菜品\*份數,序號是之前輸入的訂單記錄的序號,如果訂單中包含不能識別的菜名,則輸出“\*\* does not exist”,\*\*是不能識別的菜名
如果洗掉記錄的序號不存在,則輸出“delete error”
最后按輸入順序一次輸出每一桌所有菜品的總價(整數數值)格式:table+英文空格+桌號+“:”+英文空格+當前桌的總價
本次題目不考慮其他錯誤情況,如:桌號、選單訂單順序顛倒、不符合格式的輸入、序號重復等,在本系列的后續作業中會做要求,
輸入樣例:
麻婆豆腐 12 油淋生菜 9 table 1 2023/3/22 12/2/3 1 麻婆豆腐 2 2 2 油淋生菜 1 3 end
輸出樣例:
table 1: 1 麻婆豆腐 36 2 油淋生菜 27 table 1: 38
輸入樣例1:
麻婆豆腐 12 油淋生菜 9 table 1 2023/3/22 17/0/0 1 麻婆豆腐 2 2 2 油淋生菜 1 3 1 delete end
輸出樣例1:
table 1: 1 麻婆豆腐 36 2 油淋生菜 27 table 1: 22
輸入樣例2:
table 1: 1 麻婆豆腐 36 2 油淋生菜 27 table 1 out of opening hours
輸出樣例2:
table 1: 1 麻婆豆腐 36 2 油淋生菜 27 table 1 out of opening hours
輸入樣例3:
麻婆豆腐 12 油淋生菜 9 table 1 2022/12/5 15/03/02 1 麻婆豆腐 2 2 2 油淋生菜 1 3 3 麻辣雞絲 1 2 5 delete 7 delete table 2 2022/12/3 15/03/02 1 麻婆豆腐 2 2 2 油淋生菜 1 3 3 麻辣雞絲 1 2 7 delete end
輸出樣例3:
table 1: 1 麻婆豆腐 36 2 油淋生菜 27 麻辣雞絲 does not exist delete error; delete error; table 2: 1 麻婆豆腐 36 2 油淋生菜 27 麻辣雞絲 does not exist delete error; table 1 out of opening hours table 2: 63
輸入樣例4:
麻婆豆腐 12 油淋生菜 9 table 1 2022/12/3 19/5/12 1 麻婆豆腐 2 2 2 油淋生菜 1 3 3 麻辣雞絲 1 2 table 2 2022/12/3 15/03/02 1 麻婆豆腐 2 2 2 油淋生菜 1 3 3 麻辣雞絲 1 2 1 4 麻婆豆腐 1 1 7 delete end
輸出樣例4:
table 1: 1 麻婆豆腐 36 2 油淋生菜 27 麻辣雞絲 does not exist table 2: 1 麻婆豆腐 36 2 油淋生菜 27 麻辣雞絲 does not exist 4 table 2 pay for table 1 12 delete error; table 1: 63 table 2: 75
此題需要設計Dish類、Menu類、Record類、Order類,類與類之間存在著關聯和依賴等關系,值得注意的是,本題需要考慮訂單的格式問題,也需要考慮時間的問題,考慮營業時間及其折扣,題目敘述較長,需要記好需要實作的功能,
- 題目集五 7-5 日期問題面向物件設計(聚合一)
參考題目7-2的要求,設計如下幾個類:DateUtil、Year、Month、Day,其中年、月、日的取值范圍依然為:year∈[1900,2050] ,month∈[1,12] ,day∈[1,31] , 設計類圖如下:

應用程式共測驗三個功能:
- 求下n天
- 求前n天
- 求兩個日期相差的天數
注意:嚴禁使用Java中提供的任何與日期相關的類與方法,并提交完整原始碼,包括主類及方法(已提供,不需修改)
輸入格式:
有三種輸入方式(以輸入的第一個數字劃分[1,3]):
- 1 year month day n //測驗輸入日期的下n天
- 2 year month day n //測驗輸入日期的前n天
- 3 year1 month1 day1 year2 month2 day2 //測驗兩個日期之間相差的天數
輸出格式:
- 當輸入有誤時,輸出格式如下:
Wrong Format - 當第一個數字為1且輸入均有效,輸出格式如下:
year-month-day - 當第一個數字為2且輸入均有效,輸出格式如下:
year-month-day - 當第一個數字為3且輸入均有效,輸出格式如下:
天數值
輸入樣例1:
3 2014 2 14 2020 6 14
輸出樣例1:
2312
輸入樣例2:
2 1935 2 17 125340
輸出樣例2:
1591-12-17
輸入樣例3:
1 1999 3 28 6543
輸出樣例3:
2017-2-24
輸入樣例4:
0 2000 5 12 30
輸出樣例4:
Wrong Format
本題需要設計出Year、Month、Day三個類對時間進行處理,在類中判斷有效性、獲取前一天(月、年)或者后一天(月、年),在DateUtil類中實作輸出日期格式、判斷日期的有效性、獲取前n天和后n天的日期、獲取兩個日期間隔的天數等功能,這道題主要需要注意的是判斷日期的有效性、閏年時二月份有29天、在增減天數時需要判斷是否為日期、月份的最大最小值進行日期的改動,設計好獲取日期的前后n天后,可以直接呼叫這個方法來完成獲取日期間的天數,
代碼實作:
1 import java.util.Scanner; 2 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.print("Wrong Format"); 21 System.exit(0); 22 } 23 24 m = input.nextInt(); 25 26 if (m < 0) { 27 System.out.print("Wrong Format"); 28 System.exit(0); 29 } 30 System.out.println(date.getNextDays(m).showDate()); 31 } else if (choice == 2) { // test getPreviousNDays method 32 int n = 0; 33 year = Integer.parseInt(input.next()); 34 month = Integer.parseInt(input.next()); 35 day = Integer.parseInt(input.next()); 36 37 DateUtil date = new DateUtil(year, month, day); 38 39 if (!date.checkInputValidity()) { 40 System.out.println("Wrong Format"); 41 System.exit(0); 42 } 43 44 n = input.nextInt(); 45 46 if (n < 0) { 47 System.out.println("Wrong Format"); 48 System.exit(0); 49 } 50 System.out.println(date.getPreviousDays(n).showDate()); 51 } else if (choice == 3) { //test getDaysofDates method 52 year = Integer.parseInt(input.next()); 53 month = Integer.parseInt(input.next()); 54 day = Integer.parseInt(input.next()); 55 56 int anotherYear = Integer.parseInt(input.next()); 57 int anotherMonth = Integer.parseInt(input.next()); 58 int anotherDay = Integer.parseInt(input.next()); 59 60 DateUtil fromDate = new DateUtil(year, month, day); 61 DateUtil toDate = new DateUtil(anotherYear, anotherMonth, anotherDay); 62 63 if (fromDate.checkInputValidity() && toDate.checkInputValidity()) { 64 System.out.print(fromDate.getDaysofDates(toDate)); 65 } else { 66 System.out.print("Wrong Format"); 67 System.exit(0); 68 } 69 } 70 else{ 71 System.out.print("Wrong Format"); 72 System.exit(0); 73 } 74 75 } 76 } 77 78 79 class Year { 80 private int value; 81 public Year() { 82 83 }//無參構造方法 84 85 public Year(int value) { 86 this.value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/ value; 87 }//有參構造方法 88 89 public int getValue() { 90 return value; 91 } 92 93 public void setValue(int value) { 94 this.value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/ value; 95 } 96 97 public boolean isLeapYear() { 98 boolean isLeapYear; 99 isLeapYear = ((value % 4 == 0 && value % 100 != 0) || value % 400 == 0); 100 return isLeapYear; 101 }//判斷是否為閏年 102 103 public boolean validate() { 104 boolean validate; 105 validate = (value >= 1900 && value <= 2050); 106 return validate; 107 }//判斷年份有效性 108 109 public void yearIncrement() { 110 value++; 111 }//年份加1 112 113 public void yearReduction() { 114 value--; 115 }//年份減1 116 } 117 118 class Month { 119 private int value; 120 private Year year; 121 public Month() { 122 123 }//無參構造方法 124 125 public Month(int yearValue, int monthValue) { 126 this.year = new Year(yearValue); 127 this.value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/ monthValue; 128 }//有參構造方法 129 130 public int getValue() { 131 return value; 132 } 133 134 public void setValue(int value) { 135 this.value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/ value; 136 } 137 138 public Year getYear() { 139 return year; 140 } 141 142 public void setYear(Year year) { 143 this.year = year; 144 } 145 146 public void resetMin() { 147 value = https://www.cnblogs.com/-linfeng-/archive/2023/04/30/1; 148 }//設定月份最小值 149 150 public void resetMax() { 151 value = https://www.cnblogs.com/-linfeng-/archive/2023/04/30/12; 152 }//設定月份最大值 153 154 public boolean validate() { 155 boolean validate; 156 validate = (value >= 1 && value <= 12); 157 return validate; 158 }//判斷月份有效性 159 160 public void monthIncrement() { 161 if (validate()) { 162 if (value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/= 12) { 163 getYear().yearIncrement(); 164 resetMin(); 165 } else { 166 value++; 167 } 168 } 169 }//月份加1 170 171 public void monthReduction() { 172 if (validate()) { 173 if (value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/= 1) { 174 getYear().yearReduction(); 175 resetMax(); 176 } else { 177 value--; 178 } 179 } 180 }//月份減1 181 } 182 183 class Day { 184 private int value; 185 private Month month; 186 private int[] mon_maxnum = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 187 public Day() { 188 189 }//無參構造方法 190 191 public Day(int yearValue, int monthValue, int dayValue) { 192 this.month = new Month(yearValue, monthValue); 193 this.value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/ dayValue; 194 }//有參構造方法 195 196 public int getValue() { 197 return value; 198 } 199 200 public void setValue(int value) { 201 this.value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/ value; 202 } 203 204 public Month getMonth() { 205 return month; 206 } 207 208 public void setMonth(Month month) { 209 this.month = month; 210 } 211 212 public void resetMin() { 213 value = https://www.cnblogs.com/-linfeng-/archive/2023/04/30/1; 214 }//設定日期最小值 215 216 public void resetMax() { 217 if (validate()) { 218 value = https://www.cnblogs.com/-linfeng-/archive/2023/04/30/mon_maxnum[month.getValue() - 1]; 219 }//設定日期為該月最大日期 220 } 221 222 public boolean validate() { 223 boolean validate = false; 224 if (month.getValue() == 2 && getMonth().getYear().isLeapYear()) { 225 mon_maxnum[1] = 29; 226 } else { 227 mon_maxnum[1] = 28; 228 } 229 if (getMonth().validate()) { 230 validate = (value >= 1 && value <= mon_maxnum[month.getValue() - 1]); 231 } 232 return validate; 233 }//判斷日期有效性 234 235 public void dayIncrement() { 236 value++; 237 if (!validate()){ 238 resetMin(); 239 getMonth().monthIncrement(); 240 } 241 }//日期加1,月底時月份加1日期為1 242 243 public void dayReduction() { 244 if (value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/= 1) { 245 getMonth().monthReduction(); 246 resetMax(); 247 } else { 248 value--; 249 } 250 }//日期減1,當為日期為1時,月份減1,若是1月,年份減1 251 } 252 253 class DateUtil { 254 private Day day; 255 public DateUtil() { 256 257 } 258 259 public DateUtil(int d, int m, int y) { 260 this.day = new Day(d, m, y); 261 } 262 263 public Day getDay() { 264 return day; 265 } 266 267 public void setDay(Day d) { 268 this.day = d; 269 } 270 271 public boolean checkInputValidity() { 272 boolean checkInputValidity; 273 checkInputValidity = (getDay().validate() && getDay().getMonth().validate() 274 && getDay().getMonth().getYear().validate()); 275 return checkInputValidity; 276 }//判斷日期有效性 277 278 public boolean compareDates(DateUtil date) { 279 return (getDay().getMonth().getYear().getValue() < date.getDay().getMonth().getYear().getValue() 280 || (getDay().getMonth().getYear().getValue() == date.getDay().getMonth().getYear().getValue() && getDay().getMonth().getValue() < date.getDay().getMonth().getValue()) 281 || (getDay().getMonth().getYear().getValue() == date.getDay().getMonth().getYear().getValue() && getDay().getMonth().getValue() == date.getDay().getMonth().getValue() 282 && getDay().getValue() < date.getDay().getValue())); 283 }//比較日期比原日期大 284 285 public boolean equalTwoDates(DateUtil date) { 286 return (getDay().getMonth().getYear().getValue() == date.getDay().getMonth().getYear().getValue() 287 && getDay().getMonth().getValue() == date.getDay().getMonth().getValue() 288 && getDay().getValue() == date.getDay().getValue()); 289 }//比較兩日期相等 290 291 public String showDate() { 292 return (day.getMonth().getYear().getValue() + "-" + day.getMonth().getValue() + "-" + day.getValue()); 293 }//回傳日期格式 294 295 public DateUtil getNextDays(int n) { 296 for (int i = 0; i < n; i++) { 297 getDay().dayIncrement(); 298 } 299 return new DateUtil(this.day.getMonth().getYear().getValue(), 300 this.day.getMonth().getValue(), this.day.getValue()); 301 }//日期后n天 302 303 public DateUtil getPreviousDays(int n) { 304 for (int i = 0; i < n; i++) { 305 getDay().dayReduction(); 306 } 307 return new DateUtil(this.day.getMonth().getYear().getValue(), 308 this.day.getMonth().getValue(), this.day.getValue()); 309 }//日期前n天 310 311 public int getDaysofDates(DateUtil date) { 312 int days = 0; 313 if (compareDates(date)) { 314 while(!equalTwoDates(date)) { 315 getDay().dayIncrement(); 316 days++; 317 } 318 } else { 319 while(!equalTwoDates(date)) { 320 getDay().dayReduction(); 321 days++; 322 } 323 } 324 return days; 325 }//兩日期相差天數 326 }View Code
sourcemonitor代碼分析:


跟據sourcemonitor上分析,大部分指標處于合格范圍,但是最大復雜度有點偏高,
- 題目集五7-6 日期問題面向物件設計(聚合二)
參考題目7-3的要求,設計如下幾個類:DateUtil、Year、Month、Day,其中年、月、日的取值范圍依然為:year∈[1820,2020] ,month∈[1,12] ,day∈[1,31] , 設計類圖如下:

應用程式共測驗三個功能:
- 求下n天
- 求前n天
- 求兩個日期相差的天數
注意:嚴禁使用Java中提供的任何與日期相關的類與方法,并提交完整原始碼,包括主類及方法(已提供,不需修改)
輸入格式:
有三種輸入方式(以輸入的第一個數字劃分[1,3]):
- 1 year month day n //測驗輸入日期的下n天
- 2 year month day n //測驗輸入日期的前n天
- 3 year1 month1 day1 year2 month2 day2 //測驗兩個日期之間相差的天數
輸出格式:
- 當輸入有誤時,輸出格式如下:
Wrong Format - 當第一個數字為1且輸入均有效,輸出格式如下:
year1-month1-day1 next n days is:year2-month2-day2 - 當第一個數字為2且輸入均有效,輸出格式如下:
year1-month1-day1 previous n days is:year2-month2-day2 - 當第一個數字為3且輸入均有效,輸出格式如下:
The days between year1-month1-day1 and year2-month2-day2
輸入樣例1:
在這里給出一組輸入,例如:
3 2014 2 14 2020 6 14
輸出樣例1:
在這里給出相應的輸出,例如:
The days between 2014-2-14 and 2020-6-14 are:2312
輸入樣例2:
在這里給出一組輸入,例如:
2 1834 2 17 7821
輸出樣例2:
在這里給出相應的輸出,例如:
1834-2-17 previous 7821 days is:1812-9-19
輸入樣例3:
在這里給出一組輸入,例如:
1 1999 3 28 6543
輸出樣例3:
在這里給出相應的輸出,例如:
1999-3-28 next 6543 days is:2017-2-24
輸入樣例4:
在這里給出一組輸入,例如:
0 2000 5 12 30
輸出樣例4:
在這里給出相應的輸出,例如:
Wrong Format
同上題要求類似,但是值得注意的是需要改變年份的取值范圍,除此之外,為了滿足題目條件,還需改動類之間的關系,類中的方法也是需要改變的,實作需求的方法仍然是放在DateUtil類中進行,增加了setDayMin、setDayMax等方法,
代碼實作:
1 import java.util.Scanner; 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.print("Wrong Format"); 21 System.exit(0); 22 } 23 24 m = input.nextInt(); 25 26 if (m < 0) { 27 System.out.print("Wrong Format"); 28 System.exit(0); 29 } 30 System.out.print(date.getYear().getValue() + "-" + date.getMonth().getValue() + "-" + date.getDay().getValue() + " next " + m + " days is:"); 31 System.out.println(date.getNextNDays(m).showDate()); 32 } else if (choice == 2) { // test getPreviousNDays method 33 int n = 0; 34 year = Integer.parseInt(input.next()); 35 month = Integer.parseInt(input.next()); 36 day = Integer.parseInt(input.next()); 37 38 DateUtil date = new DateUtil(year, month, day); 39 40 if (!date.checkInputValidity()) { 41 System.out.println("Wrong Format"); 42 System.exit(0); 43 } 44 45 n = input.nextInt(); 46 47 if (n < 0) { 48 System.out.println("Wrong Format"); 49 System.exit(0); 50 } 51 System.out.print(date.getYear().getValue() + "-" + date.getMonth().getValue() + "-" + date.getDay().getValue() + " previous " + n + " days is:"); 52 System.out.println(date.getPreviousNDays(n).showDate()); 53 } else if (choice == 3) { //test getDaysofDates method 54 year = Integer.parseInt(input.next()); 55 month = Integer.parseInt(input.next()); 56 day = Integer.parseInt(input.next()); 57 58 int anotherYear = Integer.parseInt(input.next()); 59 int anotherMonth = Integer.parseInt(input.next()); 60 int anotherDay = Integer.parseInt(input.next()); 61 62 DateUtil fromDate = new DateUtil(year, month, day); 63 DateUtil toDate = new DateUtil(anotherYear, anotherMonth, anotherDay); 64 65 if (fromDate.checkInputValidity() && toDate.checkInputValidity()) { 66 System.out.print("The days between " + fromDate.showDate() + 67 " and " + toDate.showDate() + " are:" + fromDate.getDaysofDates(toDate)); 68 } else { 69 System.out.print("Wrong Format"); 70 System.exit(0); 71 } 72 } 73 else{ 74 System.out.print("Wrong Format"); 75 System.exit(0); 76 } 77 78 } 79 } 80 81 82 class Year { 83 private int value; 84 public Year() { 85 86 }//無參構造方法 87 88 public Year(int value) { 89 this.value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/ value; 90 }//有參構造方法 91 92 public int getValue() { 93 return value; 94 } 95 96 public void setValue(int value) { 97 this.value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/ value; 98 } 99 100 public boolean isLeapYear() { 101 boolean isLeapYear; 102 isLeapYear = ((value % 4 == 0 && value % 100 != 0) || value % 400 == 0); 103 return isLeapYear; 104 }//判斷是否為閏年 105 106 public boolean validate() { 107 boolean validate; 108 validate = (value >= 1820 && value <= 2020); 109 return validate; 110 }//判斷年份有效性 111 112 public void yearIncrement() { 113 value++; 114 }//年份加1 115 116 public void yearReduction() { 117 value--; 118 }//年份減1 119 } 120 121 class Month { 122 private int value; 123 public Month() { 124 125 }//無參構造方法 126 127 public Month(int value) { 128 this.value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/ value; 129 }//有參構造方法 130 131 public int getValue() { 132 return value; 133 } 134 135 public void setValue(int value) { 136 this.value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/ value; 137 } 138 139 public void resetMin() { 140 value = https://www.cnblogs.com/-linfeng-/archive/2023/04/30/1; 141 }//設定月份最小值 142 143 public void resetMax() { 144 value = https://www.cnblogs.com/-linfeng-/archive/2023/04/30/12; 145 }//設定月份最大值 146 147 public boolean validate() { 148 boolean validate; 149 validate = (value >= 1 && value <= 12); 150 return validate; 151 }//判斷月份有效性 152 153 public void monthIncrement() { 154 value++; 155 }//月份加1 156 157 public void monthReduction() { 158 value--; 159 }//月份減1 160 } 161 162 class Day { 163 private int value; 164 public Day() { 165 166 }//無參構造方法 167 168 public Day(int value) { 169 this.value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/ value; 170 }//有參構造方法 171 172 public int getValue() { 173 return value; 174 } 175 176 public void setValue(int value) { 177 this.value =https://www.cnblogs.com/-linfeng-/archive/2023/04/30/ value; 178 } 179 180 public void dayIncrement() { 181 value++; 182 }//日期加1 183 184 public void dayReduction() { 185 value--; 186 }//日期減1 187 } 188 189 class DateUtil { 190 private Year year; 191 private Month month; 192 private Day day; 193 private int[] mon_maxnum = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 194 195 public DateUtil() { 196 } 197 198 public DateUtil(int y, int m, int d) { 199 this.year = new Year(y); 200 this.month = new Month(m); 201 this.day = new Day(d); 202 } 203 204 public Year getYear() { 205 return year; 206 } 207 208 public void setYear(Year year) { 209 this.year = year; 210 } 211 212 public Month getMonth() { 213 return month; 214 } 215 216 public void setMonth(Month month) { 217 this.month = month; 218 } 219 220 public Day getDay() { 221 return day; 222 } 223 224 public void setDay(Day day) { 225 this.day = day; 226 } 227 228 public void setDayMin() { 229 day.setValue(1); 230 } 231 232 public void setDayMax() { 233 if (year.isLeapYear()) { 234 mon_maxnum[1] = 29; 235 } else { 236 mon_maxnum[1] = 28; 237 } 238 day.setValue(mon_maxnum[month.getValue() - 1]); 239 } 240 241 public boolean checkInputValidity() { 242 boolean checkInputValidity; 243 boolean day_validate = false; 244 if (year.isLeapYear()) { 245 mon_maxnum[1] = 29; 246 } else { 247 mon_maxnum[1] = 28; 248 } 249 if (getMonth().validate()) { 250 day_validate = (day.getValue() >= 1 && day.getValue() <= mon_maxnum[month.getValue() - 1]); 251 } 252 checkInputValidity = (day_validate && month.validate() && year.validate()); 253 return checkInputValidity; 254 }//判斷日期有效性 255 256 public boolean compareDates(DateUtil date) { 257 return (year.getValue() < date.year.getValue() 258 || (year.getValue() == date.year.getValue() && month.getValue() < date.month.getValue()) 259 || (year.getValue() == date.year.getValue() 260 && month.getValue() == date.month.getValue() 261 && day.getValue() < date.day.getValue())); 262 }//比較日期和原日期大小 263 264 public boolean equalTwoDates(DateUtil date) { 265 return (year.getValue() == date.year.getValue() && month.getValue() == date.month.getValue() 266 && day.getValue() == date.day.getValue()); 267 }//比較兩日期相等 268 269 public String showDate() { 270 return (year.getValue() + "-" + month.getValue() + "-" + day.getValue()); 271 }//回傳日期格式 272 273 public DateUtil getNextNDays(int n) { 274 for (int i = 0; i < n; i++) { 275 getDay().dayIncrement(); 276 if (year.isLeapYear()) { 277 mon_maxnum[1] = 29; 278 } else { 279 mon_maxnum[1] = 28; 280 } 281 if (day.getValue() > mon_maxnum[month.getValue() - 1]) { 282 month.monthIncrement(); 283 if (month.getValue() > 12) { 284 year.yearIncrement(); 285 month.resetMin(); 286 } 287 setDayMin(); 288 } 289 290 } 291 return new DateUtil(year.getValue(), month.getValue(), day.getValue()); 292 }//日期后n天 293 294 public DateUtil getPreviousNDays(int n) { 295 for (int i = 0; i < n; i++) { 296 getDay().dayReduction(); 297 if (day.getValue() < 1) { 298 month.monthReduction(); 299 if (month.getValue() < 1) { 300 year.yearReduction(); 301 month.resetMax(); 302 setDayMax(); 303 } 304 setDayMax(); 305 } 306 307 } 308 return new DateUtil(year.getValue(), month.getValue(), day.getValue()); 309 }//日期前n天 310 311 public int getDaysofDates(DateUtil date) { 312 int days = 0; 313 if (compareDates(date)) { 314 while(!equalTwoDates(date)) { 315 getDay().dayIncrement(); 316 if (year.isLeapYear()) { 317 mon_maxnum[1] = 29; 318 } else { 319 mon_maxnum[1] = 28; 320 } 321 if (day.getValue() > mon_maxnum[month.getValue() - 1]) { 322 month.monthIncrement(); 323 if (month.getValue() > 12) { 324 year.yearIncrement(); 325 month.resetMin(); 326 } 327 setDayMin(); 328 } 329 days++; 330 } 331 } else { 332 while(!equalTwoDates(date)) { 333 getDay().dayReduction(); 334 if (day.getValue() < 1) { 335 month.monthReduction(); 336 if (month.getValue() < 1) { 337 year.yearReduction(); 338 month.resetMax(); 339 setDayMax(); 340 } 341 setDayMax(); 342 } 343 days++; 344 } 345 } 346 return days; 347 }//兩日期相差天數 348 }View Code
sourcemonitor代碼分析:




- 題目集六7-4 ATM機類結構設計(一)
設計ATM仿真系統,具體要求參見作業說明,
OO作業8-1題目說明.pdf
輸入格式:
每一行輸入一次業務操作,可以輸入多行,最終以字符#終止,具體每種業務操作輸入格式如下:
- 存款、取款功能輸入資料格式:
卡號 密碼 ATM機編號 金額(由一個或多個空格分隔),
其中,當金額大于0時,代表取款,否則代表存款, - 查詢余額功能輸入資料格式:
卡號
輸出格式:
①輸入錯誤處理
- 如果輸入卡號不存在,則輸出
Sorry,this card does not exist., - 如果輸入ATM機編號不存在,則輸出
Sorry,the ATM's id is wrong., - 如果輸入銀行卡密碼錯誤,則輸出
Sorry,your password is wrong., - 如果輸入取款金額大于賬戶余額,則輸出
Sorry,your account balance is insufficient., - 如果檢測為跨行存取款,則輸出
Sorry,cross-bank withdrawal is not supported.,
②取款業務輸出
輸出共兩行,格式分別為:
[用戶姓名]在[銀行名稱]的[ATM編號]上取款¥[金額]
當前余額為¥[金額]
其中,[]說明括起來的部分為輸出屬性或變數,金額均保留兩位小數,
③存款業務輸出
輸出共兩行,格式分別為:
[用戶姓名]在[銀行名稱]的[ATM編號]上存款¥[金額]
當前余額為¥[金額]
其中,[]說明括起來的部分為輸出屬性或變數,金額均保留兩位小數,
④查詢余額業務輸出
¥[金額]
金額保留兩位小數,
輸入樣例1:
在這里給出一組輸入,例如:
6222081502001312390 88888888 06 -500.00
#
輸出樣例1:
在這里給出相應的輸出,例如:
張無忌在中國工商銀行的06號ATM機上存款¥500.00
當前余額為¥10500.00
輸入樣例2:
在這里給出一組輸入,例如:
6217000010041315709 88888888 02 3500.00
#
輸出樣例2:
在這里給出相應的輸出,例如:
楊過在中國建設銀行的02號ATM機上取款¥3500.00
當前余額為¥6500.00
輸入樣例3:
在這里給出一組輸入,例如:
6217000010041315715
#
輸出樣例3:
在這里給出相應的輸出,例如:
¥10000.00
輸入樣例4:
在這里給出一組輸入,例如:
6222081502001312390 88888888 06 -500.00
6222081502051320786 88888888 06 1200.00
6217000010041315715 88888888 02 1500.00
6217000010041315709 88888888 02 3500.00
6217000010041315715
#
輸出樣例4:
在這里給出相應的輸出,例如:
張無忌在中國工商銀行的06號ATM機上存款¥500.00
當前余額為¥10500.00
韋小寶在中國工商銀行的06號ATM機上取款¥1200.00
當前余額為¥8800.00
楊過在中國建設銀行的02號ATM機上取款¥1500.00
當前余額為¥8500.00
楊過在中國建設銀行的02號ATM機上取款¥3500.00
當前余額為¥5000.00
¥5000.00
??本題需要實作模擬簡易ATM,值得注意的是,每個人能有多個銀行賬戶,每一個賬戶可以對應多個卡號,金額是用戶總金額而不是每個賬號的金額,需要設計多個類來實作,類之間存在關聯、聚合、繼承等關系,
代碼實作:
查看代碼
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str;
Account[] account = new Account[10];
account[0] = new Account("楊過", "中國建設銀行", "3217000010041315709", 10000.00, "6217000010041315709");
account[1] = new Account("楊過", "中國建設銀行", "3217000010041315709", 10000.00, "6217000010041315715");
account[2] = new Account("楊過", "中國建設銀行", "3217000010041315715", 10000.00, "6217000010041315718");
account[3] = new Account("郭靖", "中國建設銀行", "3217000010051320007 ", 10000.00,"6217000010051320007");
account[4] = new Account("張無忌", "中國工商銀行", "3222081502001312389", 10000.00,"6222081502001312389");
account[5] = new Account("張無忌", "中國工商銀行", "3222081502001312390", 10000.00,"6222081502001312390");
account[6] = new Account("張無忌", "中國工商銀行", "3222081502001312399", 10000.00, "6222081502001312399");
account[7] = new Account("張無忌", "中國工商銀行", "3222081502001312399", 10000.00, "6222081502001312400");
account[8] = new Account("韋小寶", "中國工商銀行", "3222081502051320785", 10000.00,"6222081502051320785");
account[9] = new Account("韋小寶", "中國工商銀行", "3222081502051320786", 10000.00,"6222081502051320786");
while (true) {
str = input.nextLine();
if (str.equals("#")) {
break;
}
Bank bank = new Bank();
Card card = new Card();
ATM atm = new ATM();
Money money = new Money();
User user = new User();
String[] info = str.split("\\s+");
card.setCardNumber(info[0]);
user.setPassWord(info[1]);
atm.setATMNumber(info[2]);
money.setMoney(Double.parseDouble(info[3]));
boolean flag = false;
for (int i = 0; i <= 9; i ++) {
if (card.getCardNumber().equals(account[i].getCardNumber())) {
flag = true;
if (user.isPassWord()) {
if (atm.isATMNumber()) {
if (account[i].getBankName().equals(bank.getBankName(atm))){
money.setBalance(account[i].getBalance());
money.deposit();
if (money.judge()) {
if (money.getMoney() > 0) {
System.out.println(account[i].getUserName() + "在" + account[i].getBankName() + "的" + atm.getATMNumber() + "號ATM機上取款¥" + String.format("%.2f", Math.abs(money.getMoney())));
} else {
System.out.println(account[i].getUserName() + "在" + account[i].getBankName() + "的" + atm.getATMNumber() + "號ATM機上存款¥" + String.format("%.2f", Math.abs(money.getMoney())));
}
System.out.println("當前余額為¥" + String.format("%.2f", money.getBalance()));
}
} else {
System.out.println("Sorry,cross-bank withdrawal is not supported.");
}
}
} else {
System.out.println("Sorry,your password is wrong.");
}
}
}
if (!flag) {
System.out.println("Sorry,this card does not exist.");
}
}
}
}
class Bank {
private String bankName;
public Bank(String bankName) {
this.bankName = bankName;
}
public Bank() {
}
public String getBankName(ATM atm) {
if (atm.getATMNumber().equals("01") || atm.getATMNumber().equals("02")
|| atm.getATMNumber().equals("03") || atm.getATMNumber().equals("04")) {
bankName = "中國建設銀行";
} else if (atm.getATMNumber().equals("05") || atm.getATMNumber().equals("06")){
bankName = "中國工商銀行";
} else {
System.out.println("Sorry,the ATM's id is wrong.");
}
return bankName;
}
}
class User {
private String passWord;
public User() {
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public User(String passWord) {
this.passWord = passWord;
}
public boolean isPassWord() {
return getPassWord().equals("88888888");
}
}
class Account {
private String accountNumber;
private String bankName;
private String cardNumber;
private String userName;
private double balance;
public Account(String userName, String bankName, String accountNumber, double balance, String cardNumber) {
this.accountNumber = accountNumber;
this.bankName = bankName;
this.cardNumber = cardNumber;
this.userName = userName;
this.balance = balance;
}
public String getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}
public String getBankName() {
return bankName;
}
public void setBankName(String bankName) {
this.bankName = bankName;
}
public String getCardNumber() {
return cardNumber;
}
public void setCardNumber(String cardNumber) {
this.cardNumber = cardNumber;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
}
class ATM {
private String ATMNumber;
public ATM(String ATMNumber) {
this.ATMNumber = ATMNumber;
}
public ATM() {
}
public String getATMNumber() {
return this.ATMNumber;
}
public void setATMNumber(String ATMNumber) {
this.ATMNumber = ATMNumber;
}
public boolean isATMNumber() {
if (ATMNumber.matches("^0[1-6]$")) {
return true;
} else {
System.out.println("Sorry,the ATM's id is wrong.");
return false;
}
}
}
class Card {
private String cardNumber;
public Card() {
}
public Card(String cardNumber) {
this.cardNumber = cardNumber;
}
public String getCardNumber() {
return cardNumber;
}
public void setCardNumber(String cardNumber) {
this.cardNumber = cardNumber;
}
}
class Money {
private double balance;
private double money;
public Money(double balance) {
this.balance = balance;
}
public Money() {
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
public void deposit() {
this.balance -= money;
}
public boolean judge() {
if (balance < 0) {
System.out.println("Sorry,your account balance is insufficient.");
return false;
} else {
return true;
}
}
}
- 題目集六7-5 ATM機類結構設計(二)
OO作業9-1題目說明.pdf
輸入格式:
每一行輸入一次業務操作,可以輸入多行,最終以字符#終止,具體每種業務操作輸入格式如下:
- 取款功能輸入資料格式:
卡號 密碼 ATM機編號 金額(由一個或多個空格分隔) - 查詢余額功能輸入資料格式:
卡號
輸出格式:
①輸入錯誤處理
- 如果輸入卡號不存在,則輸出
Sorry,this card does not exist., - 如果輸入ATM機編號不存在,則輸出
Sorry,the ATM's id is wrong., - 如果輸入銀行卡密碼錯誤,則輸出
Sorry,your password is wrong., - 如果輸入取款金額大于賬戶余額,則輸出
Sorry,your account balance is insufficient.,
②取款業務輸出
輸出共兩行,格式分別為:
業務:取款 [用戶姓名]在[銀行名稱]的[ATM編號]上取款¥[金額]
當前余額為¥[金額]
其中,[]說明括起來的部分為輸出屬性或變數,金額均保留兩位小數,
③查詢余額業務輸出
業務:查詢余額 ¥[金額]
金額保留兩位小數,
輸入樣例1:
在這里給出一組輸入,例如:
6222081502001312390 88888888 06 500.00
#
輸出樣例1:
在這里給出相應的輸出,例如:
業務:取款 張無忌在中國工商銀行的06號ATM機上取款¥500.00
當前余額為¥9500.00
輸入樣例2:
在這里給出一組輸入,例如:
6217000010041315709 88888888 06 3500.00
#
輸出樣例2:
在這里給出相應的輸出,例如:
業務:取款 楊過在中國工商銀行的06號ATM機上取款¥3500.00
當前余額為¥6395.00
輸入樣例3:
在這里給出一組輸入,例如:
6217000010041315715
#
輸出樣例3:
在這里給出相應的輸出,例如:
業務:查詢余額 ¥10000.00
輸入樣例4:
在這里給出一組輸入,例如:
6222081502001312390 88888888 01 500.00
6222081502051320786 88888888 06 1200.00
6217000010041315715 88888888 02 1500.00
6217000010041315709 88888888 02 3500.00
6217000010041315715
#
輸出樣例4:
在這里給出相應的輸出,例如:
業務:取款 張無忌在中國建設銀行的01號ATM機上取款¥500.00
當前余額為¥9490.00
業務:取款 韋小寶在中國工商銀行的06號ATM機上取款¥1200.00
當前余額為¥8800.00
業務:取款 楊過在中國建設銀行的02號ATM機上取款¥1500.00
當前余額為¥8500.00
業務:取款 楊過在中國建設銀行的02號ATM機上取款¥3500.00
當前余額為¥5000.00
業務:查詢余額 ¥5000.00
輸入樣例5:
在這里給出一組輸入,例如:
6640000010045442002 88888888 09 3000
6640000010045442002 88888888 06 8000
6640000010045442003 88888888 01 10000
6640000010045442002
#
輸出樣例5:
在這里給出相應的輸出,例如:
業務:取款 張三豐在中國農業銀行的09號ATM機上取款¥3000.00
當前余額為¥6880.00
業務:取款 張三豐在中國工商銀行的06號ATM機上取款¥8000.00
當前余額為¥-1416.00
業務:取款 張三豐在中國建設銀行的01號ATM機上取款¥10000.00
當前余額為¥-11916.00
業務:查詢余額 ¥-11916.00
??本題較于上道題又添加了要求,上題不可進行跨行業務,而此題可以,除此之外,還添加了銀行個數、ATM機個數、手續費、新的用戶,值得注意的是,銀行卡分為借記卡和信用卡,整體的需求比上題增加了不少,難度自然也上升了,
三、踩坑心得
題目集5 7-5日期問題
??在寫日期有效性的時候忘記加小于等于,只是日期大于等于1小于該月份最大日期導致問題,


但是在改正后發現其他問題:

這些原本正確的測驗點出了問題,
測驗樣例:

代碼運行后的結果:

與正確答案相差了不少,跟據答案的差值不難推斷出,這相差76的問題就是出現在月份上,2014年3月份離2020年6月份剛好相差76個月,這就意味著每個月份都多計算了一天,
問題所在:

這是增加天數的寫法,若是根據這個寫法,當天數到達最后一天的時候仍然是有效的,并沒有超出月份日期最大值,因此更換為:

若是先加天數,再來進行判斷就可避免這個問題,一旦到了最大天數后,首先天數加一,若是超出了范圍則設定為1,
之前沒有出現這個問題,是因為設定的范圍到達不了最大值而是當月天數最大值減一,所以可以先判斷是否有效再加天數,但是這樣寫的問題就是,判斷天數有效性根本到不了原本月份的最后一天,例如,在一月份的30日時,因為日期有效先進行加1,此時的日期為31,但是再次判斷就不在范圍之內,就直接將日期改成1,以此類推,每一個月都會出現這樣的問題,在到達月份最大天數前,日期就改成1,每個月都會少算一天而在實際的日期后增加少的天數,故錯誤答案多了和月份數相等的天數,
改正后的結果:


四、改進建議
- ??在許多題目中,為了使程式運行結果正確,代碼中會存在不合理的地方,例如有些設計的方法沒有用上和將要實作的功能放在一個方法中實作,違背單一職責原則,一個方法中可能既要判斷又要輸出,其次,代碼中的有些陳述句可能會比較復雜,運用了多個回圈和if條件陳述句,使得代碼的復雜度大大提升,代碼的可讀性也因此降低,由于設計時考慮不周,許多題目也會出現代碼寫得很死的現象,沒有考慮其擴展性,未能給代碼一定的擴展空間,若是需要在源代碼上增加其他的功能,只能修改源代碼來實作,并沒有遵循開閉原則,
五、總結
-
- ??當遇到許多題目自身比較復雜的情況時,我在理解、設計方面仍有諸多不足,抽象思維仍需要不斷地鍛煉,對于細節處理方面還是會出現問題,這幾次的題目集可以很明顯地看出代碼量在不斷上升,難度也在不斷加大,從原本的給出類圖到不給出類圖自行設計,這就需要花費很多時間來設計,設計出現問題,代碼實作這一環節自然就會跟著出問題,最后不斷更改也只會越改越亂,
- ??之后的題目難度也會不斷上升,無論是從題目的復雜度還是代碼量都是如此,今后還是應該注重這些方面,在線上、線下課堂、輔導書上多研究,
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/551535.html
標籤:其他
上一篇:面向物件程式設計題目集總結blog2-22206110-胡瑞杰
下一篇:返回列表
