每日汇报 第七周第六天 JAVA开学考程序完成

今日学习:

  加上昨天今天JAVA开学考程序终于完成了,代码如下,在论文正文内容输出居中方面还是有问题,想不出解决方案了

  PaperManagement类:

复制代码
  1 import java.util.Scanner;
  2 import java.util.List;
  3 import java.util.ArrayList;
  4 import java.lang.StringBuilder;
  5 import org.apache.commons.lang3.StringUtils;
  6 
  7 public class PaperManagement {
  8     static int totalWidth = 59;
  9     
 10     static List<ScoreInformation> scoreList = new ArrayList<>();
 11 
 12     public static void main(String[] args) {
 13         Scanner scanner = new Scanner(System.in);
 14         int userInput;
 15         
 16         //添加学生信息
 17         scoreList.add(new ScoreInformation("20203982","薛贺程","信2005-1班","paper 1","body 1",85.0,false));
 18         //....
 19         //etc
 20         
 21         while(true) {
 22             displayMainMenu();
 23             userInput = scanner.nextInt();
 24             scanner.nextLine();
 25             switch (userInput) {
 26                 case 1:
 27                     paperSubmit(scanner);
 28                     break;
 29                 case 2:
 30                     paperPass(scanner);
 31                     break;
 32                 case 3:
 33                     paperReview(scanner);
 34                     break;
 35                 case 4:
 36                     Exit();
 37                     scanner.close();
 38                     return;
 39                 default:
 40                     System.out.println("该选项不存在");
 41             }
 42         }
 43     }
 44         
 45     
 46     
 47     public static void displayMainMenu() {
 48         
 49         System.out.println("***********************************************************");
 50         System.out.println(StringUtils.center("石家庄铁道大学软件工程系", totalWidth));
 51         System.out.println(StringUtils.center("毕业设计论文管理系统2021版", totalWidth));
 52         System.out.println("***********************************************************");
 53         System.out.println(StringUtils.center("1、毕业设计论文提交",totalWidth));
 54         System.out.println(StringUtils.center("2、毕业设计论文查重", totalWidth));
 55         System.out.println(StringUtils.center("3、毕业设计论文审查", totalWidth));
 56         System.out.println(StringUtils.center("4、退出论文管理系统", totalWidth));
 57         System.out.println("***********************************************************");
 58     }
 59     
 60 
 61     public static void paperSubmit(Scanner scanner) {
 62         
 63         String temporaryPaperTitle = " ";
 64         String temporaryPaperBody = " ";
 65         StringBuilder s1 = new StringBuilder();
 66         String result;
 67         
 68         
 69         while(true) {
 70 
 71             System.out.println("***********************************************************");
 72             System.out.println(StringUtils.center("石家庄铁道大学软件工程系毕业设计论文管理系统2021版", totalWidth));
 73             System.out.println(StringUtils.center("毕业设计论文提交", totalWidth));
 74             System.out.println("***********************************************************");
 75             System.out.println(StringUtils.center("请输入学生学号:XXXXXXXX", totalWidth));
 76             System.out.println("***********************************************************");
 77             
 78             String stunuInput = scanner.nextLine();
 79 
 80             
 81             ScoreInformation foundStudent = findStudentWay (scoreList,stunuInput);
 82             
 83             if (foundStudent!=null) {
 84                 while(true) {
 85                     
 86                 System.out.println("***********************************************************");
 87                 System.out.println(StringUtils.center("石家庄铁道大学软件工程系毕业设计论文管理系统2021版", totalWidth));
 88                 System.out.println(StringUtils.center("毕业设计论文提交", totalWidth));
 89                 System.out.println("***********************************************************");
 90                 
 91                 s1.append("学生学号:").append(foundStudent.getStun());
 92                 result = s1.toString();
 93                 s1.setLength(0);
 94                 
 95                 System.out.println(StringUtils.center(result, totalWidth));
 96                 
 97                 s1.append("学生姓名:").append(foundStudent.getName());
 98                 result = s1.toString();
 99                 s1.setLength(0);
100                 
101                 System.out.println(StringUtils.center(result, totalWidth));
102                 
103                 s1.append("所在班级:").append(foundStudent.getstuClass());
104                 result = s1.toString();
105                 s1.setLength(0);
106                 
107                 System.out.println(StringUtils.center(result, totalWidth));
108                 System.out.println(StringUtils.center("请输入毕业设计论文题目:XXXXXX XXXX", totalWidth));
109                 System.out.println("***********************************************************");
110                 
111                 
112                 String paperTitleInput = scanner.nextLine();
113                 
114                 int length = paperTitleInput.length();
115                     if ( length > 10){
116                         System.out.println("论文题目过长,请重新输入!");
117                     }else {
118                         temporaryPaperTitle = paperTitleInput;
119                         break;
120                     }
121                 
122                 }
123                 
124                 
125                 while(true) {
126                 System.out.println(StringUtils.center("请输入论文正文:",totalWidth));
127                 
128                     StringBuilder paperBodyInput = new StringBuilder();
129                     while(true) {
130                         String line = scanner.nextLine();
131                         if (line.equals("END")) {
132                             break;
133                         }
134                         paperBodyInput.append(line).append("\n");
135                     }
136                     
137                     int length = paperBodyInput.length();
138                         if ( length > 200){
139                             System.out.println("论文正文过长,请重新输入!");
140                         }else {
141                             temporaryPaperBody = paperBodyInput.toString();
142                             break;
143                         }
144                             
145                 }
146                 
147                 while(true){
148                 
149                 System.out.println("***********************************************************");
150                 System.out.println(StringUtils.center("石家庄铁道大学软件工程系毕业设计论文管理系统2021版", totalWidth));
151                 System.out.println(StringUtils.center("毕业设计论文提交", totalWidth));
152                 System.out.println("***********************************************************");
153                 
154                 s1.append("学生学号:").append(foundStudent.getStun());
155                 result = s1.toString();
156                 s1.setLength(0);
157                 
158                 System.out.println(StringUtils.center(result, totalWidth));
159                 
160                 s1.append("学生姓名:").append(foundStudent.getName());
161                 result = s1.toString();
162                 s1.setLength(0);
163                 
164                 System.out.println(StringUtils.center(result, totalWidth));
165                 
166                 s1.append("所在班级:").append(foundStudent.getstuClass());
167                 result = s1.toString();
168                 s1.setLength(0);
169                 
170                 System.out.println(StringUtils.center(result, totalWidth));
171                 
172                 s1.append("毕业设计论文题目:").append(foundStudent.getPapertitle());
173                 result = s1.toString();
174                 s1.setLength(0);
175                 
176                 System.out.println(StringUtils.center(result, totalWidth));
177                 
178                 s1.append("毕业设计论文正文:").append(foundStudent.getPaperbody());
179                 result = s1.toString();
180                 s1.setLength(0);
181                 
182                 System.out.println(StringUtils.center(result, totalWidth));
183                 System.out.println(StringUtils.center("该学生成绩已录入完毕,是否提交(Y/N)", totalWidth));
184                 System.out.println("***********************************************************");
185                 
186                 String userConfirm = scanner.nextLine();
187                 
188                 if (userConfirm.equals("Y")) {
189                     foundStudent.setPapertitle(temporaryPaperTitle);
190                     foundStudent.setPaperbody(temporaryPaperBody);
191                     return;
192                     }else if(userConfirm.equals("N")) {
193                         break;
194                     }else {
195                         System.out.println(StringUtils.center("输入有误!请重新输入", totalWidth));
196                     }
197                 }
198                 
199             }else {
200                         System.out.println(StringUtils.center("该学号不存在", totalWidth));
201             }
202         }
203 
204         
205     }
206     
207     
208     public static ScoreInformation findStudentWay (List<ScoreInformation>scoreList,String stunuInput) {
209         for (ScoreInformation student : scoreList) {
210             if(student.getStun().equals(stunuInput)) {
211                 return student;
212             }
213         }
214         return null;
215     }
216     
217     
218     public static void paperPass(Scanner scanner) {
219         
220         StringBuilder s1 = new StringBuilder();
221         String result;
222         
223         while(true) {
224             System.out.println("***********************************************************");
225             System.out.println(StringUtils.center("石家庄铁道大学软件工程系毕业设计论文管理系统2021版", totalWidth));
226             System.out.println(StringUtils.center("毕业设计论文提交", totalWidth));
227             System.out.println("***********************************************************");
228             System.out.println(StringUtils.center("请输入学生学号:XXXXXXXX", totalWidth));
229             System.out.println("***********************************************************");
230             
231             String stunuInput = scanner.nextLine();
232             
233             ScoreInformation foundStudent = findStudentWay (scoreList,stunuInput);
234             
235             if(foundStudent!=null) {
236                 while(true) {
237                     
238                     
239                     
240                     System.out.println("***********************************************************");
241                     System.out.println(StringUtils.center("石家庄铁道大学软件工程系毕业设计论文管理系统2021版", totalWidth));
242                     System.out.println(StringUtils.center("毕业设计论文查重", totalWidth));
243                     System.out.println("***********************************************************");
244                     
245                     s1.append("学生学号:").append(foundStudent.getStun());
246                     result = s1.toString();
247                     s1.setLength(0);
248                     
249                     System.out.println(StringUtils.center(result, totalWidth));
250                     
251                     s1.append("学生姓名:").append(foundStudent.getName());
252                     result = s1.toString();
253                     s1.setLength(0);
254                     
255                     System.out.println(StringUtils.center(result, totalWidth));
256                     
257                     s1.append("所在班级:").append(foundStudent.getstuClass());
258                     result = s1.toString();
259                     s1.setLength(0);
260                     
261                     System.out.println(StringUtils.center(result, totalWidth));
262                     
263                     s1.append("毕业设计论文题目:").append(foundStudent.getPapertitle());
264                     result = s1.toString();
265                     s1.setLength(0);
266                     
267                     System.out.println(StringUtils.center(result, totalWidth));
268                     
269                     s1.append("毕业设计论文正文:").append(foundStudent.getPaperbody());
270                     result = s1.toString();
271                     s1.setLength(0);
272                     
273                     System.out.println(StringUtils.center(result, totalWidth));
274                     System.out.println(StringUtils.center("请输入毕业设计论文查重率:XXX", totalWidth));
275                     System.out.println("***********************************************************");
276                     
277                     String duplicationRate = scanner.nextLine();
278                     double percentage = parsePercentage(duplicationRate);
279     
280                     if (percentage != -1.0) {
281                         System.out.println("***********************************************************");
282                         System.out.println(StringUtils.center("石家庄铁道大学软件工程系毕业设计论文管理系统2021版", totalWidth));
283                         System.out.println(StringUtils.center("毕业设计论文查重", totalWidth));
284                         System.out.println("***********************************************************");
285                         
286                         s1.append("学生学号:").append(foundStudent.getStun());
287                         result = s1.toString();
288                         s1.setLength(0);
289                         
290                         System.out.println(StringUtils.center(result, totalWidth));
291                         
292                         s1.append("学生姓名:").append(foundStudent.getName());
293                         result = s1.toString();
294                         s1.setLength(0);
295                         
296                         System.out.println(StringUtils.center(result, totalWidth));
297                         
298                         s1.append("所在班级:").append(foundStudent.getstuClass());
299                         result = s1.toString();
300                         s1.setLength(0);
301                         
302                         System.out.println(StringUtils.center(result, totalWidth));
303                         
304                         s1.append("毕业设计论文题目:").append(foundStudent.getPaperbody());
305                         result = s1.toString();
306                         s1.setLength(0);
307                         
308                         System.out.println(StringUtils.center(result, totalWidth));
309                         
310                         s1.append("毕业设计论文正文:").append(foundStudent.getPaperbody());
311                         result = s1.toString();
312                         s1.setLength(0);
313                         
314                         System.out.println(StringUtils.center(result, totalWidth));
315 
316                         s1.append("毕业设计论文查重率:").append(percentage*100).append("%");
317                         result = s1.toString();
318                         s1.setLength(0);
319                         
320                         System.out.println(StringUtils.center(result, totalWidth));
321                         System.out.println(StringUtils.center("(Y/N)", totalWidth));
322                         System.out.println("***********************************************************");
323                         
324                         String userInput = scanner.nextLine();
325                         while(true) {
326                             if(userInput.equals("Y")) {
327                                 foundStudent.setPaperpass(percentage);
328                                 break;
329                             }else if(userInput.equals("N")) {
330                                 return;
331                             }else
332                                 System.out.println(StringUtils.center("输入有误请重新输入", totalWidth));
333                         }
334                         break;
335                     }else {
336                         System.out.println(StringUtils.center("输入的百分比数据无效。", totalWidth));
337                     }
338             }
339             }else 
340                 System.out.println(StringUtils.center("该学号不存在", totalWidth));
341             
342         }
343         
344     }
345     
346     
347     public static double parsePercentage(String input) {
348         try {
349             // 去除输入中的百分号
350             String cleanedInput = input.replaceAll("%", "").trim();
351             // 将字符串转换为 double 类型,如果格式不正确,会抛出异常
352             double value = Double.parseDouble(cleanedInput);
353             // 将百分比数据转换为小数(除以 100)
354             return value / 100.0;
355         } catch (NumberFormatException e) {
356             // 格式错误,返回 -1.0 表示无效
357             return -1.0;
358         }
359     }
360     
361 
362     public static void paperReview(Scanner scanner) {
363         while(true) {
364             StringBuilder s1 = new StringBuilder();
365             String result;
366             
367             System.out.println("***********************************************************");
368             System.out.println(StringUtils.center("石家庄铁道大学软件工程系毕业设计论文管理系统2021版", totalWidth));
369             System.out.println(StringUtils.center("毕业设计论文审查", totalWidth));
370             System.out.println("***********************************************************");
371             System.out.println(StringUtils.center("请输入学生学号:XXXXXXXX", totalWidth));
372             System.out.println("***********************************************************");
373             
374             String stunuInput = scanner.nextLine();
375             
376             ScoreInformation foundStudent = findStudentWay (scoreList,stunuInput);
377             
378             if(foundStudent!=null) {
379                 while(true) {
380                     System.out.println("***********************************************************");
381                     System.out.println(StringUtils.center("石家庄铁道大学软件工程系毕业设计论文管理系统2021版", totalWidth));
382                     System.out.println(StringUtils.center("毕业设计论文查重", totalWidth));
383                     System.out.println("***********************************************************");
384                     
385                     s1.append("学生学号:").append(foundStudent.getStun());
386                     result = s1.toString();
387                     s1.setLength(0);
388                     
389                     System.out.println(StringUtils.center(result, totalWidth));
390                     
391                     s1.append("学生姓名:").append(foundStudent.getName());
392                     result = s1.toString();
393                     s1.setLength(0);
394                     
395                     System.out.println(StringUtils.center(result, totalWidth));
396                     
397                     s1.append("所在班级:").append(foundStudent.getstuClass());
398                     result = s1.toString();
399                     s1.setLength(0);
400                     
401                     System.out.println(StringUtils.center(result, totalWidth));
402                     
403                     s1.append("毕业设计论文题目:").append(foundStudent.getPaperbody());
404                     result = s1.toString();
405                     s1.setLength(0);
406                     
407                     System.out.println(StringUtils.center(result, totalWidth));
408                     
409                     s1.append("毕业设计论文正文:").append(foundStudent.getPaperbody());
410                     result = s1.toString();
411                     s1.setLength(0);
412                     
413                     System.out.println(StringUtils.center(result, totalWidth));
414                     
415                     s1.append("毕业设计论文查重率:").append(foundStudent.getPaperpass()*100).append("%");
416                     result = s1.toString();
417                     s1.setLength(0);
418                     
419                     System.out.println("***********************************************************");
420                     
421                     if(foundStudent.getPaperpass()>=0.2) {
422                         System.out.println("该学生毕业设计论文重复率超过20%,不允许进行论文审查");
423                         break;
424                     }else {
425                         
426                         System.out.println("***********************************************************");
427                         System.out.println(StringUtils.center("石家庄铁道大学软件工程系毕业设计论文管理系统2021版", totalWidth));
428                         System.out.println(StringUtils.center("毕业设计论文查重", totalWidth));
429                         System.out.println("***********************************************************");
430                         
431                         s1.append("学生学号:").append(foundStudent.getStun());
432                         result = s1.toString();
433                         s1.setLength(0);
434                         
435                         System.out.println(StringUtils.center(result, totalWidth));
436                         
437                         s1.append("学生姓名:").append(foundStudent.getName());
438                         result = s1.toString();
439                         s1.setLength(0);
440                         
441                         System.out.println(StringUtils.center(result, totalWidth));
442                         
443                         s1.append("所在班级:").append(foundStudent.getstuClass());
444                         result = s1.toString();
445                         s1.setLength(0);
446                         
447                         System.out.println(StringUtils.center(result, totalWidth));
448                         
449                         s1.append("毕业设计论文题目:").append(foundStudent.getPaperbody());
450                         result = s1.toString();
451                         s1.setLength(0);
452                         
453                         System.out.println(StringUtils.center(result, totalWidth));
454                         
455                         s1.append("毕业设计论文正文:").append(foundStudent.getPaperbody());
456                         result = s1.toString();
457                         s1.setLength(0);
458                         
459                         System.out.println(StringUtils.center(result, totalWidth));
460                         
461                         s1.append("毕业设计论文查重率:").append(foundStudent.getPaperpass()*100).append("%");
462                         result = s1.toString();
463                         s1.setLength(0);
464                         
465                         System.out.println("             是否同意该学生参加毕业设计答辩:(Y/N)              ");
466                         System.out.println("***********************************************************");
467                         
468                         String userInput = scanner.nextLine();
469                         
470                         if(userInput.equals("Y")) {
471                             foundStudent.setPaperreview(true);
472                         }else {
473                             foundStudent.setPaperreview(false);
474                             return;
475                         }
476                             
477                         
478                     }
479                     
480                     break;
481                 }
482             }else
483                 System.out.println("该学号不存在");
484         }
485 
486     }
487     
488     
489     public static void Exit() {
490         System.out.println("***********************************************************");
491         System.out.println(StringUtils.center("石家庄铁道大学软件工程系毕业设计论文管理系统2021版", totalWidth));
492         System.out.println(StringUtils.center("制作人:刘超",totalWidth));
493         System.out.println("***********************************************************");
494     }
495 }
复制代码

  ScoreInformation类:

复制代码
 1 public class ScoreInformation {
 2     private String stunumber;
 3     private String name;
 4     private String stuclass;
 5     private String papertitle;
 6     private String paperbody;
 7     private double paperpass;
 8     private boolean paperreview = false;
 9     //构造函数
10     public ScoreInformation (String stunumber,String name,String stuclass,String papertitle,String paperbody,double paperpass,boolean paperreview) {
11         this.stunumber = stunumber;
12         this.name = name;
13         this.stuclass = stuclass;
14         this.papertitle = papertitle;
15         this.paperbody = paperbody;
16         this.paperpass = paperpass;
17         this.paperreview = paperreview;
18     }
19     //get和set方法
20     public String getStun(){
21         return stunumber;
22     }
23     public void setStun(String newStunumber) {
24         stunumber = newStunumber;
25     }
26     
27     public String getName(){
28         return name;
29     }
30     public void setName(String newName) {
31         name = newName;
32     }
33     
34     public String getstuClass(){
35         return stuclass;
36     }
37     public void setClass(String newStuclass) {
38         stuclass = newStuclass;
39     }
40     
41     public String getPapertitle(){
42         return papertitle;
43     }
44     public void setPapertitle(String newPapertitle) {
45         papertitle = newPapertitle;
46     }
47     
48     public String getPaperbody(){
49         return paperbody;
50     }
51     public void setPaperbody(String newPaperbody) {
52         paperbody = newPaperbody;
53     }
54     
55     public double getPaperpass(){
56         return paperpass;
57     }
58     public void setPaperpass(double newPaperpass) {
59         paperpass = newPaperpass;
60     }
61     
62     public boolean getPaperreview(){
63         return paperreview;
64     }
65     public void setPaperreview(boolean newPaperreview) {
66         paperreview = newPaperreview;
67     }
68     
69     
70 }
复制代码

 

明日计划:

  PTA

遇到困难:maven配置,论文正文输出居中对齐

posted @   起名字真难_qmz  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· 地球OL攻略 —— 某应届生求职总结
点击右上角即可分享
微信分享提示