系統簡介:css
該系統完成學生成績錄入,修改,績點計算以及查詢學生成績的簡單操做java
設計思路:數據庫
程序分爲四大部分:成績錄入,成績修改,績點計算以及退出程序數組
成績錄入以前首先輸入學號並驗證是否存在,存在則繼續輸入並刷新屏幕,不存在則打印提示信息網絡
這裏定義輸入學號並驗證的方法,返回值爲布爾值,根據返回值使用if判斷是否繼續函數
將每一次輸入打印封裝成一個方法,即,每進行一次輸入,更新一次屏幕測試
最後封裝一個是否保存輸入的方法,即,用戶輸入Y則保存並返回true,輸入N則不保存並返回falsethis
保存的實現是總量total+1,不保存,即不加1便可spa
根據返回的true或false寫入while循環條件,便可實現頁面的返回地點.net
成績修改以前同成績輸入同樣,首先輸入學號並驗證是否存在,存在則繼續刷新屏幕,不存在則打印提示信息
這裏定義輸入學號並驗證的方法,返回值爲學號對應信息所在數組中的位置(索引)
索引的功能是後續各方法分開實現能夠經過索引獲取相應的成績信息
爲每一個科目定義修改爲績的方法
定義全局變量用來存儲舊的成績(每次只能修改一個成績因此定義一個全局變量便可),並在每一個修改爲績的方法裏在更新其新成績前給全局變量賦值爲舊成績
舊成績是當用戶輸入N,不提交保存結果時,用來將舊值再賦給原來成績時用到的
將每一個修改爲績的方法經過輸入的序號操做用switch語句集合起來,方法的返回值flag爲輸入的序號(這樣能夠記錄修改的是哪一條科目,爲後續不保存的行爲作準備)
定義是否保存函數,參數爲剛剛提到的flag即id的index,根據用戶輸入的Y或N判斷是否保存,若Y,則不進行其餘操做,若N,則將舊值set給flag標註的科目,方法返回值爲Boolean型
將該方法置於while條件中用來控制頁面的跳轉位置
績點計算以前也要輸入學號並驗證是否存在,存在則繼續刷新屏幕,不存在則打印提示信息
定義輸入學號並驗證的方法,返回值爲學號對應信息所在數組中的位置(索引)
判斷存在以後使用showpoint方法根據索引打印相應信息
if elseif else條件語句用來定義績點的值,將其封裝爲getpoint方法,參數爲科目成績
將showpoint方法返回值類型設爲Boolean,將其做爲if的條件控制是否停留在當前頁面
退出系統功能較簡單,這裏使用system.exit(-1)方法強制結束程序,並將打印結束頁面的功能一同封裝爲一個方法
ScoreManagement類源碼:
1 package stu.information.com; 2 3 import java.util.Scanner; 4 5 6 public class ScoreManagement { 7 static String[] id_list= {"20183727","20183333","20183334","20183335","20183336"}; 8 static String[] name_list= {"趙世元","張三","李四","王五","李華"}; 9 static ScoreInformation[] si_list=new ScoreInformation[10]; 10 static int total=0; 11 static double oldscore; 12 static Scanner scanner = new Scanner(System.in); 13 //打印主界面導航 14 public static void showMainNav() { 15 System.out.println("*******************************************************"); 16 System.out.println(" 石家莊鐵道大學軟件工程系"); 17 System.out.println(" 學生學籍管理系統2019版"); 18 System.out.println("*******************************************************"); 19 System.out.println(" 一、學生考試成績錄入"); 20 System.out.println(" 二、學生考試成績修改"); 21 System.out.println(" 三、計算學生成績績點"); 22 System.out.println(" 四、退出學籍管理系統"); 23 System.out.println("*******************************************************"); 24 } 25 26 //判斷學號是否存在 27 public static int isIdExist(String a) { 28 for(int i=0;i<id_list.length;i++) 29 { 30 if(id_list[i].equals(a)) 31 return i; 32 } 33 return -1; 34 } 35 36 //錄入學號 37 public static boolean addScoreInformation() { 38 System.out.print("請輸入學生學號:"); 39 String stu_id=scanner.next(); 40 if(isIdExist(stu_id)==-1) 41 { 42 System.out.println("該學號不存在!"); 43 //Runtime.getRuntime().exec("cmd /c start cls "); 44 return false; 45 } 46 else 47 { 48 si_list[total]=new ScoreInformation(); 49 si_list[total].setStunumber(stu_id); 50 si_list[total].setName(name_list[isIdExist(stu_id)]); 51 System.out.println("*******************************************************"); 52 return true; 53 } 54 } 55 56 //錄入高數成績 57 public static void addScoreInformation_second() { 58 System.out.print("學生學號:"); 59 System.out.println(si_list[total].getStunumber()); 60 System.out.print("學生姓名:"); 61 System.out.println(si_list[total].getName()); 62 System.out.print("請輸入高等數學成績:"); 63 double math=scanner.nextDouble(); 64 si_list[total].setMathematicsscore(math); 65 System.out.println("*******************************************************"); 66 } 67 68 //錄入大英成績 69 public static void addScoreInformation_third() { 70 System.out.print("學生學號:"); 71 System.out.println(si_list[total].getStunumber()); 72 System.out.print("學生姓名:"); 73 System.out.println(si_list[total].getName()); 74 System.out.print("高等數學成績:"); 75 System.out.println(si_list[total].getMathematicsscore()); 76 System.out.print("請輸入大學英語成績:"); 77 double english=scanner.nextDouble(); 78 si_list[total].setEnglishscore(english); 79 System.out.println("*******************************************************"); 80 } 81 82 //錄入計算機網絡成績 83 public static void addScoreInformation_forth() { 84 System.out.print("學生學號:"); 85 System.out.println(si_list[total].getStunumber()); 86 System.out.print("學生姓名:"); 87 System.out.println(si_list[total].getName()); 88 System.out.print("高等數學成績:"); 89 System.out.println(si_list[total].getMathematicsscore()); 90 System.out.print("大學英語成績:"); 91 System.out.println(si_list[total].getEnglishscore()); 92 System.out.print("請輸入計算機網絡成績:"); 93 double net=scanner.nextDouble(); 94 si_list[total].setNetworkscore(net); 95 System.out.println("*******************************************************"); 96 } 97 98 //錄入數據庫成績 99 public static void addScoreInformation_fifth() { 100 System.out.print("學生學號:"); 101 System.out.println(si_list[total].getStunumber()); 102 System.out.print("學生姓名:"); 103 System.out.println(si_list[total].getName()); 104 System.out.print("高等數學成績:"); 105 System.out.println(si_list[total].getMathematicsscore()); 106 System.out.print("大學英語成績:"); 107 System.out.println(si_list[total].getEnglishscore()); 108 System.out.print("計算機網絡成績:"); 109 System.out.println(si_list[total].getNetworkscore()); 110 System.out.print("請輸入數據庫成績:"); 111 double database=scanner.nextDouble(); 112 si_list[total].setDatabasescore(database); 113 System.out.println("*******************************************************"); 114 } 115 116 //錄入軟件工程成績 117 public static void addScoreInformation_sixth() { 118 System.out.print("學生學號:"); 119 System.out.println(si_list[total].getStunumber()); 120 System.out.print("學生姓名:"); 121 System.out.println(si_list[total].getName()); 122 System.out.print("高等數學成績:"); 123 System.out.println(si_list[total].getMathematicsscore()); 124 System.out.print("大學英語成績:"); 125 System.out.println(si_list[total].getEnglishscore()); 126 System.out.print("計算機網絡成績:"); 127 System.out.println(si_list[total].getNetworkscore()); 128 System.out.print("數據庫成績:"); 129 System.out.println(si_list[total].getDatabasescore()); 130 System.out.print("請輸入軟件工程成績:"); 131 double software=scanner.nextDouble(); 132 si_list[total].setSoftwarescore(software); 133 System.out.println("*******************************************************"); 134 } 135 136 //打印是否提交提示信息 137 public static void addScoreInformation_seventh() { 138 System.out.print("學生學號:"); 139 System.out.println(si_list[total].getStunumber()); 140 System.out.print("學生姓名:"); 141 System.out.println(si_list[total].getName()); 142 System.out.print("高等數學成績:"); 143 System.out.println(si_list[total].getMathematicsscore()); 144 System.out.print("大學英語成績:"); 145 System.out.println(si_list[total].getEnglishscore()); 146 System.out.print("計算機網絡成績:"); 147 System.out.println(si_list[total].getNetworkscore()); 148 System.out.print("數據庫成績:"); 149 System.out.println(si_list[total].getDatabasescore()); 150 System.out.print("軟件工程成績:"); 151 System.out.println(si_list[total].getSoftwarescore()); 152 System.out.println("該學生成績已錄入完畢,是否提交?Y/N"); 153 154 } 155 156 //是否保存錄入內容 157 public static boolean isSaveAdd() 158 { 159 String flag=scanner.next(); 160 if(flag.equals("Y")) 161 { 162 total++; 163 return true; 164 } 165 else if(flag.equals("N")) 166 { 167 System.out.println("提交操做已取消!"); 168 } 169 return false; 170 } 171 172 //錄入信息模塊標題 173 public static void showAddNav() { 174 System.out.println("*******************************************************"); 175 System.out.println(" 石家莊鐵道大學軟件工程系學生學籍管理系統2019版"); 176 System.out.println(" 學生考試成績錄入"); 177 System.out.println("*******************************************************"); 178 } 179 180 //測試打印全部 181 public static void showall() { 182 for(int i=0;i<total;i++) 183 { 184 System.out.println(si_list[i].getStunumber()+si_list[i].getName()+si_list[i].getMathematicsscore()+si_list[i].getEnglishscore() 185 +si_list[i].getNetworkscore()+si_list[i].getDatabasescore()+si_list[i].getSoftwarescore()); 186 } 187 } 188 189 //修改爲績模塊標題 190 public static void showUpdateNav() { 191 System.out.println("*******************************************************"); 192 System.out.println(" 石家莊鐵道大學軟件工程系學生學籍管理系統2019版"); 193 System.out.println(" 學生考試成績修改界面"); 194 System.out.println("*******************************************************"); 195 } 196 197 //根據學號獲取索引 198 public static int getIndex(String a) { 199 for(int i=0;i<total;i++) 200 { 201 if(si_list[i].getStunumber().equals(a)) 202 return i; 203 } 204 return -1; 205 } 206 207 //修改爲績時輸入學號 208 public static String updateInputNum() { 209 System.out.print("請輸入學生學號:"); 210 String stu_id=scanner.next(); 211 if(isIdExist(stu_id)==-1) 212 { 213 System.out.println("該學號不存在!"); 214 //Runtime.getRuntime().exec("cmd /c start cls "); 215 return null; 216 } 217 else 218 { 219 si_list[total]=new ScoreInformation(); 220 si_list[total].setStunumber(stu_id); 221 si_list[total].setName(name_list[isIdExist(stu_id)]); 222 System.out.println("*******************************************************"); 223 return stu_id; 224 } 225 } 226 227 //打印成績信息 228 public static void showScore(int i) { 229 System.out.println("學生學號:"+si_list[i].getStunumber()); 230 System.out.println("學生姓名:"+si_list[i].getName()); 231 System.out.println("一、高等數學成績:"+si_list[i].getMathematicsscore()); 232 System.out.println("二、大學英語成績:"+si_list[i].getEnglishscore()); 233 System.out.println("三、計算機網絡成績:"+si_list[i].getNetworkscore()); 234 System.out.println("四、數據庫成績:"+si_list[i].getDatabasescore()); 235 System.out.println("五、軟件工程成績:"+si_list[i].getSoftwarescore()); 236 } 237 238 //打印姓名學號 239 public static void showUpdateIDandName(int i) { 240 showUpdateNav(); 241 System.out.println("學生學號:"+si_list[i].getStunumber()); 242 System.out.println("學生姓名:"+si_list[i].getName()); 243 } 244 245 //修改高數成績 246 public static double updateMath(int i) { 247 showUpdateIDandName(i); 248 System.out.print("請輸入修改後高等數學成績:"); 249 double old=si_list[i].getMathematicsscore(); 250 double math=scanner.nextDouble(); 251 si_list[i].setMathematicsscore(math); 252 return old; 253 } 254 //修改大英成績 255 public static double updateEnglish(int i) { 256 showUpdateIDandName(i); 257 System.out.print("請輸入修改後大學英語成績:"); 258 double old=si_list[i].getEnglishscore(); 259 double English=scanner.nextDouble(); 260 si_list[i].setEnglishscore(English); 261 return old; 262 } 263 //修改網絡成績 264 public static double updateNet(int i) { 265 showUpdateIDandName(i); 266 System.out.print("請輸入修改後計算機網絡成績:"); 267 double old=si_list[i].getNetworkscore(); 268 double net=scanner.nextDouble(); 269 si_list[i].setNetworkscore(net); 270 return old; 271 } 272 //修改數據庫成績 273 public static double updateDatabase(int i) { 274 showUpdateIDandName(i); 275 System.out.print("請輸入修改後數據庫成績:"); 276 double old=si_list[i].getDatabasescore(); 277 double database=scanner.nextDouble(); 278 si_list[i].setDatabasescore(database); 279 return old; 280 } 281 //修改軟工成績 282 public static double updateSoftware(int i) { 283 showUpdateIDandName(i); 284 System.out.print("請輸入修改後軟件工程成績:"); 285 double old=si_list[i].getSoftwarescore(); 286 double software=scanner.nextDouble(); 287 si_list[i].setSoftwarescore(software); 288 return old; 289 } 290 291 //修改爲績方法 292 public static int updateScore(int i) { 293 int flag; 294 flag=scanner.nextInt(); 295 switch (flag) { 296 case 1: 297 oldscore=updateMath(i); 298 break; 299 case 2: 300 oldscore=updateEnglish(i); 301 break; 302 case 3: 303 oldscore=updateNet(i); 304 break; 305 case 4: 306 oldscore=updateDatabase(i); 307 break; 308 case 5: 309 oldscore=updateSoftware(i); 310 break; 311 312 default: 313 System.out.println("該選項不存在!"); 314 break; 315 } 316 return flag; 317 } 318 319 //是否保存 320 public static boolean isSaveUpdate(int i,int index) { 321 System.out.println("該學生信息已修改完畢,是否提交?Y/N"); 322 String flag=scanner.next(); 323 if(flag.equals("N")) 324 { 325 switch (i) { 326 case 1: 327 si_list[index].setMathematicsscore(oldscore); 328 break; 329 case 2: 330 si_list[index].setEnglishscore(oldscore); 331 break; 332 case 3: 333 si_list[index].setNetworkscore(oldscore); 334 break; 335 case 4: 336 si_list[index].setDatabasescore(oldscore); 337 break; 338 case 5: 339 si_list[index].setSoftwarescore(oldscore); 340 break; 341 342 default: 343 break; 344 } 345 System.out.println("提交操做已取消!"); 346 return false; 347 } 348 showMainNav(); 349 return true; 350 } 351 352 //退出系統 353 public static void exitProgram() { 354 System.out.println("*****************************************************************"); 355 System.out.println(" 感謝使用石家莊鐵道大學軟件工程系學生學籍管理系統2019版"); 356 System.out.println(" 製做人:趙世元"); 357 System.out.println("*****************************************************************"); 358 System.exit(-1); 359 } 360 361 //打印績點計算界面 362 public static void showCalPoint() { 363 System.out.println("*******************************************************"); 364 System.out.println(" 石家莊鐵道大學軟件工程系學生學籍管理系統2019版"); 365 System.out.println(" 學生考試成績績點計算界面"); 366 System.out.println("*******************************************************"); 367 } 368 369 public static double getPoint(double a) { 370 if(a>=90) 371 return 4.0; 372 else if(a>=85&&a<89.9) 373 return 3.7; 374 else if(a>=82&&a<84.9) 375 return 3.3; 376 else if(a>=78&&a<81.9) 377 return 3.0; 378 else if(a>=75&&a<77.9) 379 return 2.7; 380 else if(a>=72&&a<74.9) 381 return 2.3; 382 else if(a>=68&&a<71.9) 383 return 2.0; 384 else if(a>=66&&a<67.9) 385 return 1.5; 386 else if(a>=60&&a<63.9) 387 return 1.0; 388 else 389 return 0; 390 } 391 392 public static boolean showPoint(int i) { 393 System.out.println("學生學號:"+si_list[i].getStunumber()); 394 System.out.println("學生姓名:"+si_list[i].getName()); 395 double math=getPoint(si_list[i].getMathematicsscore()); 396 double english=getPoint(si_list[i].getEnglishscore()); 397 double net=getPoint(si_list[i].getNetworkscore()); 398 double database=getPoint(si_list[i].getDatabasescore()); 399 double software=getPoint(si_list[i].getSoftwarescore()); 400 System.out.println("一、高等數學成績績點:"+math); 401 System.out.println("二、大學英語成績績點:"+english); 402 System.out.println("三、計算機網絡成績績點:"+net); 403 System.out.println("四、數據庫成績績點:"+database); 404 System.out.println("五、軟件工程成績績點:"+software); 405 double average=(math*4+english*3+net*4+database*3+software*2)/(4+3+4+3+2); 406 String result = String.format("%.2f", average); 407 System.out.println("你的平均學分績點爲:"+result); 408 if(average>=2) 409 System.out.println("提示信息:你的學分績點已達到畢業要求!"); 410 else 411 System.out.println("提示信息:你的學分績點不知足畢業要求!"); 412 System.out.println("是否返回系統主界面?Y/N"); 413 String flag=scanner.next(); 414 if(flag.equals("Y")) 415 return true; 416 return false; 417 } 418 419 public static void main(String[] args) throws InterruptedException { 420 // TODO 自動生成的方法存根 421 int flag; 422 showMainNav(); 423 String id; 424 425 for(;;) 426 { 427 flag=scanner.nextInt(); 428 switch (flag) { 429 case 1: 430 showAddNav(); 431 if(addScoreInformation()) 432 { 433 addScoreInformation_second(); 434 addScoreInformation_third(); 435 addScoreInformation_forth(); 436 addScoreInformation_fifth(); 437 addScoreInformation_sixth(); 438 addScoreInformation_seventh(); 439 440 while(isSaveAdd()==false) 441 { 442 showAddNav(); 443 if(addScoreInformation()) 444 { 445 addScoreInformation_second(); 446 addScoreInformation_third(); 447 addScoreInformation_forth(); 448 addScoreInformation_fifth(); 449 addScoreInformation_sixth(); 450 addScoreInformation_seventh(); 451 } 452 } 453 } 454 break; 455 case 2: 456 showUpdateNav(); 457 if((id=updateInputNum())!=null) 458 { 459 int index=getIndex(id); 460 showScore(index); 461 int f=updateScore(index); 462 while(isSaveUpdate(f, index)==false) 463 { 464 showUpdateNav(); 465 if((id=updateInputNum())!=null) 466 { 467 index=getIndex(id); 468 showScore(index); 469 f=updateScore(index); 470 } 471 } 472 } 473 break; 474 case 3: 475 showCalPoint(); 476 if((id=updateInputNum())!=null) 477 { 478 int index=getIndex(id); 479 if(showPoint(index)==false) 480 Thread.sleep(60000);
481 } 482 break; 483 case 4: 484 exitProgram(); 485 break; 486 default: 487 System.out.println("該選項不存在!"); 488 break; 489 } 490 showMainNav(); 491 } 492 } 493 }
ScoreInformation類源碼:
1 package stu.information.com; 2 3 public class ScoreInformation { 4 private String stunumber; 5 private String name; 6 private double mathematicsscore; 7 private double englishscore; 8 private double networkscore; 9 private double databasescore; 10 private double softwarescore; 11 public String getStunumber() { 12 return stunumber; 13 } 14 public void setStunumber(String stunumber) { 15 this.stunumber = stunumber; 16 } 17 public String getName() { 18 return name; 19 } 20 public void setName(String name) { 21 this.name = name; 22 } 23 public double getMathematicsscore() { 24 return mathematicsscore; 25 } 26 public void setMathematicsscore(double mathematicsscore) { 27 this.mathematicsscore = mathematicsscore; 28 } 29 public double getEnglishscore() { 30 return englishscore; 31 } 32 public void setEnglishscore(double englishscore) { 33 this.englishscore = englishscore; 34 } 35 public double getNetworkscore() { 36 return networkscore; 37 } 38 public void setNetworkscore(double networkscore) { 39 this.networkscore = networkscore; 40 } 41 public double getDatabasescore() { 42 return databasescore; 43 } 44 public void setDatabasescore(double databasescore) { 45 this.databasescore = databasescore; 46 } 47 public double getSoftwarescore() { 48 return softwarescore; 49 } 50 public void setSoftwarescore(double softwarescore) { 51 this.softwarescore = softwarescore; 52 } 53 }
運行效果以下: