Person.java:
public class Person {
private String name;
private String sex;
private int age;
public Person(){};
public Person(String name,String sex,int age)
{
this.name=name;
this.sex=sex;
this.age=age;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
Student.java:
import java.util.*;
public class Student extends Person {
private long number;
private int phi;
private int eng;
private int comp;
private int[] num;
public Student(){};
public Student(String name,String sex,int age,long number,int phi,int eng,int comp)
{
super(name,sex,age);
this.number=number;
this.phi=phi;
this.eng=eng;
this.comp=comp;
}
public int getComp() {
return comp;
}
public void setComp(int comp) {
this.comp = comp;
}
public int getEng() {
return eng;
}
public void setEng(int eng) {
this.eng = eng;
}
public long getNumber() {
return number;
}
public void setNumber(long number) {
this.number = number;
}
public int getPhi() {
return phi;
}
public void setPhi(int phi) {
this.phi = phi;
}
//求平均分数
public double avg()
{
return (getPhi()+getEng()+getComp())/3;
}
public int max()
{
sort();
return num[num.length-1];
}
public int min()
{
sort();
return num[0];
}
private void sort()
{
num=new int[]{getPhi(),getEng(),getComp()};
Arrays.sort(num);
}
public String toString()
{
return "学号:"+getNumber()+" 名字:"+getName()+" 性别:"+getSex()+" 平均分:"+avg()+" 最高分:"+max()+" 最低分:"+min();
}
}
测试类:
Test.java:
public class Test {
public static void main(String[] args) {
Student s=new Student("张三","男",20,11203,80,70,90);
System.out.println(s);
}
}
温馨提示:答案为网友推荐,仅供参考