3、定义一个表示学生信息的类Student,要求如下: (1)类Student的成员变量: sNO 表示学号;sName表示姓名;sSex表示性别;sAge表示年龄;sJava:表示Java课程成绩。 (2)类Student带参数的构造方法: 在构造方法中通过形参完成对成员变量的赋值操作。 (3)类Student的方法成员: l getNo():获得学号; l getName():获得姓名; l getSex():获得性别; l getAge()获得年龄; l getJava():获得Java 课程成绩 根据类Student的定义,创建五个该类的对象,输出每个学生的信息,计算并输出这五个学生Java语言成绩的平均值,以及计算并输出他们Java语言成绩的最大值和最小值。
时间: 2023-05-30 21:02:33 浏览: 305
代码如下:
```
public class Student {
private String sNO;
private String sName;
private String sSex;
private int sAge;
private double sJava;
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 lgetNo() {
return sNO;
}
public String lgetName() {
return sName;
}
public String lgetSex() {
return sSex;
}
public int lgetAge() {
return sAge;
}
public double lgetJava() {
return sJava;
}
}
public class Main {
public static void main(String[] args) {
Student s1 = new Student("001", "张三", "男", 20, 89.5);
Student s2 = new Student("002", "李四", "女", 19, 92.0);
Student s3 = new Student("003", "王五", "男", 21, 85.5);
Student s4 = new Student("004", "赵六", "女", 20, 90.5);
Student s5 = new Student("005", "周七", "男", 22, 88.0);
System.out.println("学生信息:");
System.out.println(s1.lgetNo() + " " + s1.lgetName() + " " + s1.lgetSex() + " " + s1.lgetAge() + " " + s1.lgetJava());
System.out.println(s2.lgetNo() + " " + s2.lgetName() + " " + s2.lgetSex() + " " + s2.lgetAge() + " " + s2.lgetJava());
System.out.println(s3.lgetNo() + " " + s3.lgetName() + " " + s3.lgetSex() + " " + s3.lgetAge() + " " + s3.lgetJava());
System.out.println(s4.lgetNo() + " " + s4.lgetName() + " " + s4.lgetSex() + " " + s4.lgetAge() + " " + s4.lgetJava());
System.out.println(s5.lgetNo() + " " + s5.lgetName() + " " + s5.lgetSex() + " " + s5.lgetAge() + " " + s5.lgetJava());
double sum = s1.lgetJava() + s2.lgetJava() + s3.lgetJava() + s4.lgetJava() + s5.lgetJava();
double avg = sum / 5;
System.out.println("Java语言成绩平均值:" + avg);
double max = s1.lgetJava();
if (s2.lgetJava() > max) {
max = s2.lgetJava();
}
if (s3.lgetJava() > max) {
max = s3.lgetJava();
}
if (s4.lgetJava() > max) {
max = s4.lgetJava();
}
if (s5.lgetJava() > max) {
max = s5.lgetJava();
}
System.out.println("Java语言成绩最大值:" + max);
double min = s1.lgetJava();
if (s2.lgetJava() < min) {
min = s2.lgetJava();
}
if (s3.lgetJava() < min) {
min = s3.lgetJava();
}
if (s4.lgetJava() < min) {
min = s4.lgetJava();
}
if (s5.lgetJava() < min) {
min = s5.lgetJava();
}
System.out.println("Java语言成绩最小值:" + min);
}
}
```
阅读全文