定义一个Person类和它的子类Student。Person类有姓名、性别、年龄和邮箱。然后定义一个方法showMessage()输出个人信息。Student类有学号、班级、Java成绩、计算机网络成绩、c语言成绩、高等数学成绩和英语成绩。定义方法showMessage()用于输出学生的信息,用方法average()求学生五个科目的平均分并输出。
定义一个表示学生信息的类Student,要求如下,(有关类的编程)
(1) 类Student的成员变量:
sNo 表示学号;sName:表示姓名;sSex:表示性别;sAge:表示年龄;sJava:表示JAVA成绩;sMath:表示数学科目成绩,sC:表示c语言成绩;sEnglish:表示英语成绩,sChinese:表示语文成绩;
(2)类Student带参数的构造方法:
在构造方法中通过形参完成对成员变量的赋值操作。
(3)类Student的方法成员:
getNo();获得学号:
getName():获得姓名:
getSex ():获得性别
getAge():获得年龄
getJava(): 获得Java成绩
getMath:获得数学科目成绩
getC:获得c语言的成绩
getEnglish:获得英语成绩
getChinese:获得语文成绩
根据类Student的定义,创建该类的对象,输出学生的信息,把五门科目成绩按升序输出并计算输出这五门科目的最高分、最低分和平均分。
@Test
public void test001(){
class Person{
private String name;
private String sSex;
private Integer sAge;
private String email;
Person(String name,String sSex,Integer sAge,String email){
this.name = name;
this.sSex= sSex;
this.sAge = sAge;
this.email = email;
}
public void showMeaasge() {
System.out.println("Person{" + "name='" + name + '\'' + ", sSex='" + sSex + '\'' + ", sAge='" + sAge + '\'' + ", email='"
+ email + '\'' + '}');
}
}
class Student extends Person{
private String sNo;
private String className;
private double sJava;
private double computerScore;
private double sC;
private double sMath;
private double sEnglish;
private double sChinese;
Student(String name,String sSex,Integer sAge,String email,String sNo,String className,double sJava,
double computerScore,double sC,double sMath,double sEnglish,double sChinese){
super(name,sSex, sAge, email);
this.sNo = sNo;
this.className = className;
this.sJava = sJava;
this.computerScore = computerScore;
this.sC = sC;
this.sMath = sMath;
this.sEnglish = sEnglish;
this.sChinese = sChinese;
}
public void showMeaasge(){
System.out.println("Student{" + "sNo='" + sNo + '\'' + ", className='" + className + '\'' + ", sJava=" + sJava
+ ", computerScore=" + computerScore + ", sC=" + sC + ", sMath=" + sMath + ", sEnglish=" + sEnglish
+ ", sChinese=" + sChinese + '}');
}
public void average(){
System.out.println("平均分:"+(sJava+computerScore+sC+sMath+sEnglish+sChinese)/6);
}
public String getName() {
return super.name;
}
public String getsSex() {
return super.sSex;
}
public Integer getsAge() {
return super.sAge;
}
public double getsJava() {
return sJava;
}
public double getsC() {
return sC;
}
public double getsMath() {
return sMath;
}
public double getsEnglish() {
return sEnglish;
}
public double getsChinese() {
return sChinese;
}
public double getComputerScore() {
return computerScore;
}
}
Student student = new Student("张三","男",18,"123@163.com","001","一班",10,
20,30,40,50,60);
student.average();
List<Double> scoreList = new ArrayList<>();
scoreList.add(student.getsJava());
scoreList.add(student.getsMath());
scoreList.add(student.getsC());
scoreList.add(student.getsEnglish());
scoreList.add(student.getsChinese());
scoreList.add(student.getComputerScore());
double highScore = scoreList.get(0);
double lowScore = scoreList.get(0);
for(double score : scoreList){
if(score>highScore){
highScore = score;
}
if(score<lowScore){
lowScore = score;
}
}
System.out.println("最高分:"+highScore);
System.out.println("最低分:"+lowScore);
}
你题目里给了6个科目,要求只输出五科的平均数,全给你写上自己删掉不需要的科目就行了
定义person类,再写student 类继承person类,实现成员方法等
咱不是挺简单的嘛
Student重写父类输出信息方法,将学科成绩放入集合中排序然后输出排序后的学科成绩,最高分最低分从集合头尾去拿,平均分自己算一下,或者用stream分别得到最高,最低,平均
这?,不是挺好写的吗,最基本的