java作业。。。

完成下面父类及子类的声明
(1) 声明Student类属性包括学号、姓名、英语成绩、数学成绩、计算机成绩和总成绩。方法包括构造方法、get方法、 set方法、toString方法、equals方法、compare方法(比较两个学生的总成绩,结果分为大于、小于、等于),sum方法(计算总成绩)和testScore方法(计算评测成绩)。
注:评测成绩可以取三门课成绩的平均分,另外任何一门课的成绩的改变都需要对总成绩进行重新计算,因此,在每一个set方法中应调用sum方法计算总成绩。
(2)声明StudentXW(学习委员)类为Student类的子类。
在StudentXW类中增加责任属性,并重写testScore方法(评测成绩=三门课平均分+3)
(3)声明StudentBZ类为Student类的子类
在StudentBZ类中增加责任属性,并重写testScore方法(评测成绩=三门课平均分+5)
4)声明测试类,生成若干个Student类、StudentXW类及StudentBZ类对象,并分别计算它们的评测成绩(建议采用:写一个测试函数,该函数以父类student数组作为参数) 。

package java作业;

public class Hzf_7 {

    public static void main(String[] args) {
        Student ww = new Student(14060490,"王五",50,90,80);
        ww.sum();
        System.out.println("王五的测评成绩为:"+ww.testScore());

        StudentXW zs = new StudentXW(14060441,"张三",50,60,40);
        zs.sum();
        System.out.println("张三的测评成绩为:"+zs.testScore());

        StudentXW ls = new StudentXW(14060442,"李四",80,50,70);
        ls.sum();
        System.out.println("李四的测评成绩为:"+ls.testScore());

    }

}

class Student{
    private int nbr;//学号
    private String name;//姓名
    private float english_scores;//英语成绩
    private float math_scores;//数学成绩
    private float computer_scores;//计算机成绩
    private float total = 0;//总成绩
    //定义空构造方法
    public Student(){}
    //定义构造方法为属性初始化
    public Student(int nbr, String name, float english_scores, float math_scores, float computer_scores) {
        super();
        this.nbr = nbr;
        this.name = name;
        this.english_scores = english_scores;
        this.math_scores = math_scores;
        this.computer_scores = computer_scores;
    }
    //定义获取学号方法
    public int getNbr() {
        return nbr;
    }
    //定义设置学号方法
    public void setNbr(int nbr) {
        this.nbr = nbr;
    }
    //定义过去姓名方法
    public String getName() {
        return name;
    }
    //定义设置姓名方法
    public void setName(String name) {
        this.name = name;
    }
    //定义获取英语成绩方法
    public float getEnglishScores() {
        return english_scores;
    }
    //定义设置英语成绩方法
    public void setEnglishScores(float english_scores) {
        this.english_scores = english_scores;
        total+=english_scores;
    }
    //定义获取数学成绩方法
    public float getMathScores() {
        return math_scores;
    }
    //定义设置数学成绩方法
    public void setMathScores(float math_scores) {
        this.math_scores = math_scores;
        total+=math_scores;
    }
    //定义获取计算机成绩方法
    public float getComputerScores() {
        return computer_scores;
    }
    //定义设置计算机成绩方法
    public void setComputerScores(float computer_scores) {
        this.computer_scores = computer_scores;
        total+=computer_scores;
    }
    //定义获取总成绩方法
    public float getTotal() {
        return total;
    }
    //定义设置总成绩方法
    public void setTotal(float total) {
        this.total = total;
    }
    //定义toString方法
    public String toString() {
        String str=this.nbr+"..."+this.name+"..."+
        this.english_scores+"..."+this.math_scores+"..."+
        this.computer_scores+"..."+this.total;
        return str;
    }
    //定义compare方法
    public int compare(Student stu) {
        int result=0;
        if(this.total>stu.getTotal()){
            result=1;//大于
        }else if(this.total==stu.getTotal()){
            result =0;//等于
        }else if(this.total<stu.getTotal()){
            result=-1;//小于
        }
        return result;
    }
    //定义sum方法
    public void sum(){
        this.total=(this.english_scores+this.math_scores+this.computer_scores);
    }
    //定义testScore方法
    public double testScore(){
        return  ((this.total*1.0d)/3.0);
    }

}
//定义StudentXW继承Student
class StudentXW extends Student{
    private String zr;//责任
    //定义构造方法为属性初始化
    public StudentXW(int nbr, String name, float english_scores, float math_scores, float computer_scores) {
        super(nbr,name,english_scores,math_scores,computer_scores);
        this.zr = "收作业";
    }
    //定义获取学委责任方法
    public String getZr() {
        return zr;
    }
    //重写父类testScore方法
    public double testScore(){
        return super.testScore()+3;//调用父类的testScore方法并+3
    }

}
//定义StudentBZ继承Student
class StudentBZ extends Student{
    private String zr;//班长责任
    //定义构造方法为属性初始化
    public StudentBZ(int nbr, String name, float english_scores, float math_scores, float computer_scores) {
        super(nbr,name,english_scores,math_scores,computer_scores);
        this.zr = "协同辅导员管理班级";
    }
    //定义获取学委责任方法
    public String getZr() {
        return zr;
    }
    //定义获取班长责任的方法
    public String getBz() {
        return zr;
    }
    //重写父类testScore方法
    public double testScore(){
        return super.testScore()+5;//调用父类的testScore方法并+5
    }
}
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值