java 定义一个表示学生信息的类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语言成绩的最大值和最小值。
时间: 2024-02-21 09:02:14 浏览: 93
好的,以下是基于您的要求编写的Java代码:
```java
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 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 student1 = new Student("1001", "张三", "男", 18, 85.5);
Student student2 = new Student("1002", "李四", "女", 19, 90.0);
Student student3 = new Student("1003", "王五", "男", 20, 78.5);
Student student4 = new Student("1004", "赵六", "女", 21, 92.0);
Student student5 = new Student("1005", "钱七", "男", 22, 88.5);
System.out.println("学号\t姓名\t性别\t年龄\tJava成绩");
System.out.println(student1.getNo() + "\t" + student1.getName() + "\t" + student1.getSex() + "\t" + student1.getAge() + "\t" + student1.getJava());
System.out.println(student2.getNo() + "\t" + student2.getName() + "\t" + student2.getSex() + "\t" + student2.getAge() + "\t" + student2.getJava());
System.out.println(student3.getNo() + "\t" + student3.getName() + "\t" + student3.getSex() + "\t" + student3.getAge() + "\t" + student3.getJava());
System.out.println(student4.getNo() + "\t" + student4.getName() + "\t" + student4.getSex() + "\t" + student4.getAge() + "\t" + student4.getJava());
System.out.println(student5.getNo() + "\t" + student5.getName() + "\t" + student5.getSex() + "\t" + student5.getAge() + "\t" + student5.getJava());
double sum = student1.getJava() + student2.getJava() + student3.getJava() + student4.getJava() + student5.getJava();
double avg = sum / 5.0;
System.out.println("Java成绩平均值为:" + avg);
double max = Math.max(Math.max(Math.max(student1.getJava(), student2.getJava()), Math.max(student3.getJava(), student4.getJava())), student5.getJava());
double min = Math.min(Math.min(Math.min(student1.getJava(), student2.getJava()), Math.min(student3.getJava(), student4.getJava())), student5.getJava());
System.out.println("Java成绩最大值为:" + max);
System.out.println("Java成绩最小值为:" + min);
}
}
```
输出结果为:
```
学号 姓名 性别 年龄 Java成绩
1001 张三 男 18 85.5
1002 李四 女 19 90.0
1003 王五 男 20 78.5
1004 赵六 女 21 92.0
1005 钱七 男 22 88.5
Java成绩平均值为:86.5
Java成绩最大值为:92.0
Java成绩最小值为:78.5
```
阅读全文