[20-05-01][Self-test 29]Java Pass or Fail

Posted mirai3usi9

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[20-05-01][Self-test 29]Java Pass or Fail相关的知识,希望对你有一定的参考价值。

 1 package test_6_3;
 2 
 3 public class Student {
 4 
 5     /**
 6      * 编写一个程序,统计学生成绩,其功能包括输入学生的姓名和成绩,
 7      * 按成绩从高到低排列打印输出,对前%70的学生定为合格(PASS),而后30%的学生定为不合格(FAIL)
 8      */
 9     
10     public String name;
11     public int score;
12     
13     public Student(String name, int score) {
14         
15         this.name = name;
16         this.score = score;
17     }
18     
19 }

 

 1 package test_6_3;
 2 
 3 public class Deal {
 4     
 5     public void sort(Student[] students) {
 6         
 7         for (int i = 0; i < students.length - 1; i++) {
 8             for (int j = i + 1; j < students.length; j++) {
 9                 if (students[i].score < students[j].score) {
10                     Student temp = students[i];
11                     students[i] = students[j];
12                     students[j] = temp;
13                 }
14             }
15             
16         }
17     
18     }
19 
20     public void deal(Student[] students) {
21         
22         sort(students);
23         
24         for (int i = 0; i < students.length; i++) {
25             
26             if (i + 1 <= students.length * 0.7) {
27                 System.out.println("姓名:" + students[i].name + ",成绩:" + students[i].score + ",PASS");
28             } else {
29                 System.out.println("姓名:" + students[i].name + ",成绩:" + students[i].score + ",FAIL");
30             }
31         }
32     }
33 
34 }

 

 1 package test_6_3;
 2 
 3 public class Test {
 4 
 5     public static void main(String[] args) {
 6         
 7         Student[] students = new Student[5];
 8         
 9         students[0] = new Student("Joker", 90);
10         students[1] = new Student("Navi", 100);
11         students[2] = new Student("Violet", 90);
12         students[3] = new Student("Skull", 20);
13         students[4] = new Student("Panther", 80);
14         
15         Deal deal = new Deal();
16         
17         deal.deal(students);
18 
19     }
20 
21 }

 

结果如下:

姓名:Navi,成绩:100,PASS
姓名:Joker,成绩:90,PASS
姓名:Violet,成绩:90,PASS
姓名:Panther,成绩:80,FAIL
姓名:Skull,成绩:20,FAIL

以上是关于[20-05-01][Self-test 29]Java Pass or Fail的主要内容,如果未能解决你的问题,请参考以下文章

[20-05-01][Self-test 28]Java Students' Score

[20-04-26][Self-test 6]Java CharType

[20-05-09][Self-test 40]Java BankSystem 1

[20-05-09][Self-test 40]Java BankSystem 1

[20-06-04][Self-test 46]Java Linker Manage

[20-06-04][Self-test 46]Java Linker Manage