请用java写一个学生管理系统中通常都会涉及到学生类,请定义该类,包括学号、姓名、性别、年龄、班级、 Python 成绩、 JAVA 成绩、 Web 前端技术成绩等属性以及计算总成绩、平均成绩等方法;分别输出五位学生的完整信息,每名学生的总成绩、平均成绩, Python 成绩最高学生的姓名以及 Python 成绩的均值 +
时间: 2023-06-24 19:05:58 浏览: 148
学生信息管理系统,实现学生信息包括:学号、姓名、性别、年龄、班级等信息。
5星 · 资源好评率100%
以下是Java代码实现:
```java
public class Student {
private int id;
private String name;
private String gender;
private int age;
private String className;
private int pythonScore;
private int javaScore;
private int webScore;
public Student(int id, String name, String gender, int age, String className,
int pythonScore, int javaScore, int webScore) {
this.id = id;
this.name = name;
this.gender = gender;
this.age = age;
this.className = className;
this.pythonScore = pythonScore;
this.javaScore = javaScore;
this.webScore = webScore;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public int getAge() {
return age;
}
public String getClassName() {
return className;
}
public int getPythonScore() {
return pythonScore;
}
public int getJavaScore() {
return javaScore;
}
public int getWebScore() {
return webScore;
}
public int getTotalScore() {
return pythonScore + javaScore + webScore;
}
public double getAverageScore() {
return getTotalScore() / 3.0;
}
public static void main(String[] args) {
Student[] students = new Student[5];
students[0] = new Student(1001, "张三", "男", 20, "计算机科学与技术", 90, 85, 80);
students[1] = new Student(1002, "李四", "女", 19, "软件工程", 88, 92, 85);
students[2] = new Student(1003, "王五", "男", 21, "网络工程", 92, 90, 95);
students[3] = new Student(1004, "赵六", "女", 20, "计算机科学与技术", 85, 80, 90);
students[4] = new Student(1005, "钱七", "男", 22, "软件工程", 95, 94, 92);
for (Student student : students) {
System.out.println("学号:" + student.getId()
+ ",姓名:" + student.getName()
+ ",性别:" + student.getGender()
+ ",年龄:" + student.getAge()
+ ",班级:" + student.getClassName()
+ ",Python成绩:" + student.getPythonScore()
+ ",Java成绩:" + student.getJavaScore()
+ ",Web前端技术成绩:" + student.getWebScore());
}
int maxPythonScore = -1;
String maxPythonScoreName = null;
double pythonScoreSum = 0.0;
for (Student student : students) {
int pythonScore = student.getPythonScore();
if (pythonScore > maxPythonScore) {
maxPythonScore = pythonScore;
maxPythonScoreName = student.getName();
}
pythonScoreSum += pythonScore;
}
double pythonScoreAvg = pythonScoreSum / students.length;
for (Student student : students) {
System.out.println(student.getName() + "的总成绩为:" + student.getTotalScore()
+ ",平均成绩为:" + student.getAverageScore());
}
System.out.println("Python成绩最高的学生是:" + maxPythonScoreName
+ ",Python成绩的平均值为:" + pythonScoreAvg);
}
}
```
输出结果:
```
学号:1001,姓名:张三,性别:男,年龄:20,班级:计算机科学与技术,Python成绩:90,Java成绩:85,Web前端技术成绩:80
学号:1002,姓名:李四,性别:女,年龄:19,班级:软件工程,Python成绩:88,Java成绩:92,Web前端技术成绩:85
学号:1003,姓名:王五,性别:男,年龄:21,班级:网络工程,Python成绩:92,Java成绩:90,Web前端技术成绩:95
学号:1004,姓名:赵六,性别:女,年龄:20,班级:计算机科学与技术,Python成绩:85,Java成绩:80,Web前端技术成绩:90
学号:1005,姓名:钱七,性别:男,年龄:22,班级:软件工程,Python成绩:95,Java成绩:94,Web前端技术成绩:92
张三的总成绩为:255,平均成绩为:85.0
李四的总成绩为:265,平均成绩为:88.33333333333333
王五的总成绩为:277,平均成绩为:92.33333333333333
赵六的总成绩为:255,平均成绩为:85.0
钱七的总成绩为:281,平均成绩为:93.66666666666667
Python成绩最高的学生是:钱七,Python成绩的平均值为:90.0
```
阅读全文