酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

学生信息管理类:(1)设计一个student的类,该类用于存储学生的学号、姓名、语文成绩和数学成绩;(2)包含两个成员方法。一个是计算学生总成绩,另一个是计算学生平均成绩的。(3)使用static关键字实现一个静态变量studentcount来统计创建的学生对象的个数。提供一个静态方法,用于输出当前学生对象的总数。(4)输出学生的姓名、学号、总成绩、平均成绩和当前学生总数。用java实现

```java public class Student { private int id; private String name; private double chineseScore; private double mathScore; private static int studentCount = 0; public Student(int id, String name, double chineseScore, double mathScore) { this.id = id; this.name = name; this.chineseScore = chineseScore; this.mathScore = mathScore; studentCount++; } public double getTotalScore() { return chineseScore + mathScore; } public double getAverageScore() { return (chineseScore + mathScore) / 2; } public static void printStudentCount() { System.out.println("当前学生总数为:" + studentCount); } public void printStudentInfo() { System.out.println("姓名:" + name); System.out.println("学号:" + id); System.out.println("总成绩:" + getTotalScore()); System.out.println("平均成绩:" + getAverageScore()); System.out.println("----------------------------------"); } public static void main(String[] args) { Student student1 = new Student(1, "张三", 85, 90); Student student2 = new Student(2, "李四", 78, 88); student1.printStudentInfo(); student2.printStudentInfo(); Student.printStudentCount(); } } ``` 运行结果: ``` 姓名:张三 学号:1 总成绩:175.0 平均成绩:87.5 ---------------------------------- 姓名:李四 学号:2 总成绩:166.0 平均成绩:83.0 ---------------------------------- 当前学生总数为:2 ``` [2024-09-29 16:14:21 | AI写代码神器 | 1026点数解答]

相关提问