第一次在课堂上限定时间做的时候,着急、思绪混乱,输入都有问题,好在最后解决了。
昨天安静下来认真写完,测试一遍没有问题,但是仔细想,又二次加工了一下,之前测试No的情况没有发现,最终写成如下版本:
(后悔没把昨天第一次写的保存了,不然就可以看到不封装成函数有多崩溃,血淋淋的教训!)
1 package up; 2 3 public class information { 4 private String num; 5 private String name; 6 private double math; 7 private double eng; 8 private double net; 9 private double data; 10 private double soft; 11 public information() {} 12 13 public String getNum() { 14 return num; 15 } 16 17 public void setNum(String num) { 18 this.num = num; 19 } 20 21 public String getName() { 22 return name; 23 } 24 25 public void setName(String name) { 26 this.name = name; 27 } 28 29 public double getMath() { 30 return math; 31 } 32 33 public void setMath(double math) { 34 this.math = math; 35 } 36 37 public double getEng() { 38 return eng; 39 } 40 41 public void setEng(double eng) { 42 this.eng = eng; 43 } 44 45 public double getNet() { 46 return net; 47 } 48 49 public void setNet(double net) { 50 this.net = net; 51 } 52 53 public double getData() { 54 return data; 55 } 56 57 public void setData(double data) { 58 this.data = data; 59 } 60 61 public double getSoft() { 62 return soft; 63 } 64 65 public void setSoft(double soft) { 66 this.soft = soft; 67 } 68 69 public information(String num,String name,double math,double eng,double net,double data,double soft) 70 { 71 num = " "; 72 name = " "; 73 math = 0; 74 eng = 0; 75 net = 0; 76 data = 0; 77 soft = 0; 78 } 79 80 }
1 package up; 2 3 import java.util.Scanner; 4 5 public class management { 6 7 static information [] stu = new information[100]; 8 static String []nums = {"20180001","20180002","20180003","20180004","20183613"}; 9 static String []names = {"aaa","bbb","ccc","ddd","薛瑞瑾"}; 10 static int sum=0; 11 static Scanner input=new Scanner(System.in); 12 static double old; 13 14 public static void menu()//主菜单 15 { 16 System.out.println("***********************************************************\n" + 17 " 石家庄铁道大学软件工程系\n" + 18 " 学生学籍管理系统 2019 版\n" + 19 "***********************************************************\n" + 20 " 1、 学生考试成绩录入\n " + 21 " 2、 学生考试成绩修改 \n " + 22 " 3、 计算学生成绩绩点 \n " + 23 " 4、退出学籍管理系统 \n "+ 24 "********************************************************** \n"); 25 } 26 public static void first()//录入最初界面 27 { 28 System.out.println("***********************************************************\n" + 29 " 石家庄铁道大学软件工程系\n" + 30 " 考试成绩录入\n" + 31 "***********************************************************\n" + 32 " 请输入学生学号: \n"+ 33 "***********************************************************"); 34 } 35 public static void first1()//录入界面头 36 { 37 System.out.println("***********************************************************\n" + 38 " 石家庄铁道大学软件工程系\n" + 39 " 学生考试成绩录入界面\n" + 40 "***********************************************************"); 41 } 42 public static void second()//修改最初界面 43 { 44 System.out.println("***********************************************************\n" + 45 " 石家庄铁道大学软件工程系\n" + 46 " 考试成绩修改\n" + 47 "***********************************************************\n" + 48 " 请输入学生学号: \n"+ 49 "***********************************************************"); 50 51 } 52 public static void third()//绩点最初界面 53 { 54 System.out.println("***********************************************************\n" + 55 " 石家庄铁道大学软件工程系\n" + 56 " 考试成绩绩点计算\n" + 57 "***********************************************************\n" + 58 " 请输入学生学号: \n"+ 59 "***********************************************************"); 60 } 61 public static void third1()//绩点界面头 62 { 63 System.out.println("***********************************************************\n" + 64 " 石家庄铁道大学软件工程系\n" + 65 " 考试成绩绩点计算界面\n" + 66 "***********************************************************"); 67 } 68 public static boolean Input()//判断学号是否在数据库中 69 { 70 int i,n=0; 71 String num = input.next(); 72 for (i=0;i<5;i++) 73 { 74 if(num.equals(nums[i])) 75 { 76 n=1; 77 stu[sum]=new information(); 78 stu[sum].setNum(nums[i]); 79 stu[sum].setName(names[i]); 80 break; 81 } 82 } 83 if(n==0) 84 { 85 System.out.println("学号不存在!\n"); 86 first(); 87 return false; 88 } 89 return true; 90 } 91 public static int judge()//找到学生的位置 92 { 93 int i,n=0; 94 String num = input.next(); 95 for (i=0;i<5;i++) 96 { 97 if(num.equals(stu[i].getNum())) 98 { 99 n=1; 100 break; 101 } 102 } 103 if(n==0) 104 { 105 System.out.println("学号不存在!\n"); 106 first(); 107 return -1; 108 } 109 return i; 110 } 111 public static void add()//录入 112 { 113 double math,eng,net,soft,data; 114 first(); 115 while(Input()==false); 116 first1(); 117 System.out.println("学生学号:"+stu[sum].getNum()); 118 System.out.println("学号姓名:"+stu[sum].getName()); 119 System.out.println("请输入高数成绩:"); 120 System.out.println("***********************************************************"); 121 math = input.nextDouble(); 122 stu[sum].setMath(math); 123 first1(); 124 System.out.println("学生学号:"+stu[sum].getNum()); 125 System.out.println("学号姓名:"+stu[sum].getName()); 126 System.out.println("高数成绩:"+stu[sum].getMath()); 127 System.out.println("请输入英语成绩:"); 128 System.out.println("***********************************************************"); 129 eng = input.nextDouble(); 130 stu[sum].setEng(eng); 131 first1(); 132 System.out.println("学生学号:"+stu[sum].getNum()); 133 System.out.println("学号姓名:"+stu[sum].getName()); 134 System.out.println("高数成绩:"+stu[sum].getMath()); 135 System.out.println("英语成绩:"+stu[sum].getEng()); 136 System.out.println("请输入计网成绩:"); 137 System.out.println("***********************************************************"); 138 net = input.nextDouble(); 139 stu[sum].setNet(net); 140 first1(); 141 System.out.println("学生学号:"+stu[sum].getNum()); 142 System.out.println("学号姓名:"+stu[sum].getName()); 143 System.out.println("高数成绩:"+stu[sum].getMath()); 144 System.out.println("英语成绩:"+stu[sum].getEng()); 145 System.out.println("计网成绩:"+stu[sum].getNet()); 146 System.out.println("请输入数据库成绩:"); 147 System.out.println("***********************************************************"); 148 data = input.nextDouble(); 149 stu[sum].setData(data); 150 first1(); 151 System.out.println("学生学号:"+stu[sum].getNum()); 152 System.out.println("学号姓名:"+stu[sum].getName()); 153 System.out.println("高数成绩:"+stu[sum].getMath()); 154 System.out.println("英语成绩:"+stu[sum].getEng()); 155 System.out.println("计网成绩:"+stu[sum].getNet()); 156 System.out.println("数据库成绩:"+stu[sum].getData()); 157 System.out.println("请输入软工成绩:"); 158 System.out.println("***********************************************************"); 159 soft = input.nextDouble(); 160 stu[sum].setSoft(soft); 161 first1(); 162 System.out.println("学生学号:"+stu[sum].getNum()); 163 System.out.println("学号姓名:"+stu[sum].getName()); 164 System.out.println("高数成绩:"+stu[sum].getMath()); 165 System.out.println("英语成绩:"+stu[sum].getEng()); 166 System.out.println("计网成绩:"+stu[sum].getNet()); 167 System.out.println("数据库成绩:"+stu[sum].getData()); 168 System.out.println("软工成绩:"+stu[sum].getSoft()); 169 } 170 public static boolean isorno() //录入是否提交 171 { 172 System.out.println("该学生已录入完毕,是否提交(Y/N)"); 173 System.out.println("***********************************************************"); 174 String flag = input.next(); 175 String s = "Y"; 176 if(flag.equals(s)) 177 { 178 sum++; 179 System.out.println("已提交!"); 180 return true; 181 } 182 else 183 { 184 System.out.println("未保存!"); 185 return false; 186 187 } 188 } 189 public static void changemath(int j) 190 { 191 double math; 192 System.out.println("学生学号:"+stu[j].getNum()); 193 System.out.println("学号姓名:"+stu[j].getName()); 194 System.out.println("请输入修改后的高数成绩:"); 195 math = input.nextDouble(); 196 old = stu[j].getMath(); 197 stu[j].setMath(math); 198 System.out.println("学生学号:"+stu[j].getNum()); 199 System.out.println("学号姓名:"+stu[j].getName()); 200 System.out.println("1、高数成绩:"+stu[j].getMath()); 201 System.out.println("2、英语成绩:"+stu[j].getEng()); 202 System.out.println("3、计网成绩:"+stu[j].getNet()); 203 System.out.println("4、数据库成绩:"+stu[j].getData()); 204 System.out.println("5、软工成绩:"+stu[j].getSoft()); 205 } 206 public static void changeeng(int j) 207 { 208 double eng; 209 System.out.println("学生学号:"+stu[j].getNum()); 210 System.out.println("学号姓名:"+stu[j].getName()); 211 System.out.println("请输入修改后的高数成绩:"); 212 eng = input.nextDouble(); 213 old = stu[j].getEng(); 214 stu[j].setEng(eng); 215 System.out.println("学生学号:"+stu[j].getNum()); 216 System.out.println("学号姓名:"+stu[j].getName()); 217 System.out.println("1、高数成绩:"+stu[j].getMath()); 218 System.out.println("2、英语成绩:"+stu[j].getEng()); 219 System.out.println("3、计网成绩:"+stu[j].getNet()); 220 System.out.println("4、数据库成绩:"+stu[j].getData()); 221 System.out.println("5、软工成绩:"+stu[j].getSoft()); 222 } 223 public static void changenet(int j) 224 { 225 double net; 226 System.out.println("学生学号:"+stu[j].getNum()); 227 System.out.println("学号姓名:"+stu[j].getName()); 228 System.out.println("请输入修改后的高数成绩:"); 229 net = input.nextDouble(); 230 old = stu[j].getNet(); 231 stu[j].setNet(net); 232 System.out.println("学生学号:"+stu[j].getNum()); 233 System.out.println("学号姓名:"+stu[j].getName()); 234 System.out.println("1、高数成绩:"+stu[j].getMath()); 235 System.out.println("2、英语成绩:"+stu[j].getEng()); 236 System.out.println("3、计网成绩:"+stu[j].getNet()); 237 System.out.println("4、数据库成绩:"+stu[j].getData()); 238 System.out.println("5、软工成绩:"+stu[j].getSoft()); 239 } 240 public static void changedata(int j) 241 { 242 double data; 243 System.out.println("学生学号:"+stu[j].getNum()); 244 System.out.println("学号姓名:"+stu[j].getName()); 245 System.out.println("请输入修改后的高数成绩:"); 246 data = input.nextDouble(); 247 old = stu[j].getData(); 248 stu[j].setData(data); 249 System.out.println("学生学号:"+stu[j].getNum()); 250 System.out.println("学号姓名:"+stu[j].getName()); 251 System.out.println("1、高数成绩:"+stu[j].getMath()); 252 System.out.println("2、英语成绩:"+stu[j].getEng()); 253 System.out.println("3、计网成绩:"+stu[j].getNet()); 254 System.out.println("4、数据库成绩:"+stu[j].getData()); 255 System.out.println("5、软工成绩:"+stu[j].getSoft()); 256 } 257 public static void changesoft(int j) 258 { 259 double soft; 260 System.out.println("学生学号:"+stu[j].getNum()); 261 System.out.println("学号姓名:"+stu[j].getName()); 262 System.out.println("请输入修改后的高数成绩:"); 263 soft = input.nextDouble(); 264 old = stu[j].getSoft(); 265 stu[j].setSoft(soft); 266 System.out.println("学生学号:"+stu[j].getNum()); 267 System.out.println("学号姓名:"+stu[j].getName()); 268 System.out.println("1、高数成绩:"+stu[j].getMath()); 269 System.out.println("2、英语成绩:"+stu[j].getEng()); 270 System.out.println("3、计网成绩:"+stu[j].getNet()); 271 System.out.println("4、数据库成绩:"+stu[j].getData()); 272 System.out.println("5、软工成绩:"+stu[j].getSoft()); 273 } 274 public static int second1()//修改界面头 275 { 276 int j; 277 second(); 278 while((j=judge())==-1); 279 System.out.println("学生学号:"+stu[j].getNum()); 280 System.out.println("学号姓名:"+stu[j].getName()); 281 System.out.println("1、高数成绩:"+stu[j].getMath()); 282 System.out.println("2、英语成绩:"+stu[j].getEng()); 283 System.out.println("3、计网成绩:"+stu[j].getNet()); 284 System.out.println("4、数据库成绩:"+stu[j].getData()); 285 System.out.println("5、软工成绩:"+stu[j].getSoft()); 286 System.out.println("请选择要修改的成绩:"); 287 return j; 288 } 289 public static int which(int j)//改哪一个成绩 290 { 291 int choice1 = input.nextInt(); 292 first1(); 293 switch(choice1) 294 { 295 case 1: 296 changemath(j); 297 break; 298 case 2: 299 changeeng(j); 300 break; 301 case 3: 302 changenet(j); 303 break; 304 case 4: 305 changedata(j); 306 break; 307 case 5: 308 changesoft(j); 309 break; 310 } 311 return choice1; 312 } 313 public static boolean yesorno(int choice1,int j)//修改是否提交 314 { 315 System.out.println("该学生已录入完毕,是否提交(Y/N)"); 316 System.out.println("***********************************************************"); 317 String flag = input.next(); 318 String s = "Y"; 319 if(flag.equals(s)) 320 { 321 System.out.println("已提交!"); 322 return true; 323 } 324 else 325 { 326 switch(choice1) 327 { 328 case 1: 329 stu[j].setMath(old); 330 break; 331 case 2: 332 stu[j].setEng(old); 333 break; 334 case 3: 335 stu[j].setNet(old); 336 break; 337 case 4: 338 stu[j].setData(old); 339 break; 340 case 5: 341 stu[j].setSoft(old); 342 break; 343 } 344 return false; 345 } 346 } 347 public static double getjidian(double x) 348 { 349 double temp; 350 if(x>=90 && x<=100) 351 temp = 4.0; 352 else if(x>=85 && x<=89.9) 353 temp = 3.7; 354 else if(x>=82 && x<=84.9) 355 temp = 3.3; 356 else if(x>=78 && x<=81.9) 357 temp = 3.0; 358 else if(x>=75 && x<=77.9) 359 temp = 2.7; 360 else if(x>=72 && x<=74.9) 361 temp = 2.3; 362 else if(x>=68 && x<=71.9) 363 temp = 2.0; 364 else if(x>=66 && x<=67.9) 365 temp = 1.7; 366 else if(x>=64 && x<=65.9) 367 temp = 1.3; 368 else if(x>=60 && x<=63.9) 369 temp = 1.0; 370 else 371 temp = 0; 372 return temp; 373 } 374 375 public static void main(String[] args) { 376 int i,n=0; 377 378 menu(); 379 System.out.println("请选择:\n"); 380 int choice = input.nextInt(); 381 while(1<=choice&&choice<=4) 382 { 383 switch(choice) 384 { 385 case 1://录入 386 { 387 add(); 388 while(isorno()==false) 389 add(); 390 break; 391 } 392 case 2://修改 393 { 394 int j,choice1; 395 j=second1(); 396 choice1 = which(j); 397 while(yesorno(choice1, j)==false) 398 { 399 j = second1(); 400 choice1 = which(j); 401 } 402 break; 403 } 404 case 3: 405 { 406 int index; 407 third(); 408 index = judge(); 409 double mathjd,engjd,netjd,datajd,softjd,ave; 410 mathjd = getjidian(stu[index].getMath()); 411 engjd = getjidian(stu[index].getEng()); 412 netjd = getjidian(stu[index].getNet()); 413 datajd = getjidian(stu[index].getData()); 414 softjd = getjidian(stu[index].getSoft()); 415 ave = mathjd*4/16+engjd*3/16+netjd*4/16+datajd*3/16+softjd*2/16; 416 third1(); 417 System.out.println("学生学号:"+stu[index].getNum()); 418 System.out.println("学号姓名:"+stu[index].getName()); 419 System.out.println("1、数学绩点:"+mathjd); 420 System.out.println("2、英语绩点:"+engjd); 421 System.out.println("3、计网绩点:"+netjd); 422 System.out.println("4、数据库绩点:"+datajd); 423 System.out.println("5、软工绩点:"+softjd); 424 System.out.println("你的平均学分绩点:"+ave); 425 if(ave>=2) 426 { 427 System.out.println("提示信息:你的学分绩点已达到毕业要求!"); 428 } 429 else 430 { 431 System.out.println("提示信息:你的学分绩点不满足毕业要求!"); 432 } 433 System.out.println("是否返回系统主界面(Y/N)"); 434 System.out.println("***********************************************************"); 435 String flag = input.next(); 436 String s = "Y"; 437 if(flag.equals(s)) 438 { 439 menu(); 440 } 441 else 442 { 443 System.out.println("无操作"); 444 } 445 break; 446 } 447 case 4: 448 System.out.println("***********************************************************"); 449 System.out.println(" 谢谢使用石家庄铁道大学软件工程系学生学籍管理系统 2019 版 "); 450 System.out.println(" 制作人:薛瑞瑾"); 451 System.out.println("***********************************************************"); 452 System.exit(0); 453 break; 454 } 455 // TODO Auto-generated method stub 456 menu(); 457 System.out.println("请选择:\n"); 458 input=new Scanner(System.in); 459 choice = input.nextInt(); 460 } 461 462 463 } 464 465 }