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

Posted mirai3usi9

tags:

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

 1 package test_6_2;
 2 
 3 public class Student {
 4 
 5     /**
 6      * 编写一个程序,已有若干学生数据,包括学号、姓名、成绩,要求输出这些学生数据并计算平均分。
 7      */
 8     
 9     public static int stuNum;
10     public static double totalScore;
11     
12     public String code;
13     public String name;
14     public double score;
15     
16     public Student() {
17         
18     }
19     
20     public Student(String code, String name, double score) {
21         
22         this.code = code;
23         this.name = name;
24         this.score = score;
25         
26         System.out.println("学号:" + this.code + ",姓名:" + this.name + ",成绩:" + this.score);
27         
28         stuNum++;
29         totalScore += score;
30     }
31     
32     public void avg() {
33         
34         System.out.println("平均分是:" + totalScore / stuNum);
35     }
36     
37 }

 

 1 package test_6_2;
 2 
 3 public class Test {
 4 
 5     public static void main(String[] args) {
 6 
 7         Student s1 = new Student("01", "Joker", 90);
 8         Student s2 = new Student("02", "Navi", 100);
 9         Student s3 = new Student("03", "Skull", 20);
10         Student s4 = new Student("04", "Violet", 90);
11         
12         s1.avg();
13 
14     }
15 
16 }

 

结果如下:

学号:01,姓名:Joker,成绩:90.0
学号:02,姓名:Navi,成绩:100.0
学号:03,姓名:Skull,成绩:20.0
学号:04,姓名:Violet,成绩:90.0
平均分是:75.0

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

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

[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