1、【编程题】定义一个表示学生信息的类Student,要求如下: (1)类Student的成员变量: sNO 表示学号;sName表示姓名;sSex表示性别;sAge表示年龄;sJava:表示Java课程成绩。 (2)类Student带参数的构造方法: 在构造方法中通过形参完成对成员变量的赋值操作。 (3)类Student的方法成员: getNo():获得学号; getName():获得姓名; getSex():获得性别; getAge()获得年龄; getJava():获得Java 课程成绩 根据类Student的定义,创建五个该类的对象,输出每个学生的信息,计算并输出这五个学生Java语言成绩的平均值,以及计算并输出他们Java语言成绩的最大值和最小值。(100 分)
时间: 2024-03-27 11:38:48 浏览: 150
设计一个学生类Student(学生学号、姓名、数学、英语、计算机成绩;)
5星 · 资源好评率100%
以下是代码实现:
```java
public class Student {
private String sNO; // 学号
private String sName; // 姓名
private String sSex; // 性别
private int sAge; // 年龄
private double sJava; // Java成绩
public Student(String sNO, String sName, String sSex, int sAge, double sJava) {
this.sNO = sNO;
this.sName = sName;
this.sSex = sSex;
this.sAge = sAge;
this.sJava = sJava;
}
public String getNo() {
return sNO;
}
public String getName() {
return sName;
}
public String getSex() {
return sSex;
}
public int getAge() {
return sAge;
}
public double getJava() {
return sJava;
}
}
public class Main {
public static void main(String[] args) {
Student stu1 = new Student("001", "Tom", "男", 18, 80.0);
Student stu2 = new Student("002", "Jerry", "男", 19, 90.0);
Student stu3 = new Student("003", "Lucy", "女", 20, 85.0);
Student stu4 = new Student("004", "Lily", "女", 18, 92.0);
Student stu5 = new Student("005", "Mike", "男", 20, 88.0);
System.out.println("学生信息:");
System.out.println(stu1.getNo() + " " + stu1.getName() + " " + stu1.getSex() + " " + stu1.getAge() + " " + stu1.getJava());
System.out.println(stu2.getNo() + " " + stu2.getName() + " " + stu2.getSex() + " " + stu2.getAge() + " " + stu2.getJava());
System.out.println(stu3.getNo() + " " + stu3.getName() + " " + stu3.getSex() + " " + stu3.getAge() + " " + stu3.getJava());
System.out.println(stu4.getNo() + " " + stu4.getName() + " " + stu4.getSex() + " " + stu4.getAge() + " " + stu4.getJava());
System.out.println(stu5.getNo() + " " + stu5.getName() + " " + stu5.getSex() + " " + stu5.getAge() + " " + stu5.getJava());
double sum = stu1.getJava() + stu2.getJava() + stu3.getJava() + stu4.getJava() + stu5.getJava();
double avg = sum / 5;
System.out.println("Java成绩平均值:" + avg);
double max = stu1.getJava();
double min = stu1.getJava();
if (stu2.getJava() > max) max = stu2.getJava();
if (stu3.getJava() > max) max = stu3.getJava();
if (stu4.getJava() > max) max = stu4.getJava();
if (stu5.getJava() > max) max = stu5.getJava();
if (stu2.getJava() < min) min = stu2.getJava();
if (stu3.getJava() < min) min = stu3.getJava();
if (stu4.getJava() < min) min = stu4.getJava();
if (stu5.getJava() < min) min = stu5.getJava();
System.out.println("Java成绩最大值:" + max);
System.out.println("Java成绩最小值:" + min);
}
}
```
输出结果:
```
学生信息:
001 Tom 男 18 80.0
002 Jerry 男 19 90.0
003 Lucy 女 20 85.0
004 Lily 女 18 92.0
005 Mike 男 20 88.0
Java成绩平均值:87.0
Java成绩最大值:92.0
Java成绩最小值:80.0
```
阅读全文