当前位置: 代码迷 >> Java相关 >> kkk考试题,大家帮小弟我一上
  详细解决方案

kkk考试题,大家帮小弟我一上

热度:7732   发布时间:2013-02-25 21:44:27.0
kkk考试题,大家帮我一下啊
三、 编程题(45分)
完成下面父类及子类的声明:
1、 声明Student类。(20分)
属性包括学号、姓名、英语成绩、数学成绩、计算机成绩。
方法包括:
a) 构造方法:初始化所有属性;
b) 每一个属性的get方法和set方法:get方法用来得到属性的值,set方法用来设置属性的值;
c) toString方法:返回各个属性信息;提示:返回类型为String
d) sum方法:计算总成绩;
e) compare方法:比较两个学生的总成绩,结果分为大于、小于、等于;提示:返回类型为String
f) testScore方法:计算测评成绩(测评成绩即三门课成绩的平均分)
2、 声明StudentXW(学习委员)类为Student类的子类。(10分)
a) 增加属性:责任
b) 添加构造方法:实现各属性的初始化;
c) 添加“责任”属性的get方法和set方法;
d) 重写testScore方法:评测成绩=三门课成绩的平均分+3;
3、 声明StudentBZ(班长)类为Student类的子类。(10分)
a) 增加属性:责任
b) 添加构造方法:实现各属性的初始化;
c) 添加“责任”属性的get方法和set方法;
d) 重写testScore方法:评测成绩=三门课成绩的平均分+5;
4、 声明测试类,生成若干个Student类、StudentXW类及StudentBZ类对象,并分别计算它们的评测成绩。(5分)


------解决方案--------------------------------------------------------
学习要自己动手.你要自己动手才可以得到进步...

我就提供一个类吧!后面的你可以学习学习..这个其实是很简单的,我就用很简单的方法给你!

Java code
package test;public class Student {//    学号、姓名、英语成绩、数学成绩、计算机成绩。    String number;    String name;    int engScore;    int mathScore;    int compScore;    public String getNumber() {        return number;    }    public void setNumber(String number) {        this.number = number;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public int getEngScore() {        return engScore;    }    public void setEngScore(int engScore) {        this.engScore = engScore;    }    public int getMathScore() {        return mathScore;    }    public void setMathScore(int mathScore) {        this.mathScore = mathScore;    }    public int getCompScore() {        return compScore;    }    public void setCompScore(int compScore) {        this.compScore = compScore;    }            public Student(){}        public Student(        String number,        String name,        int engScore,        int mathScore,        int compScore) {                this.setName(name);        this.setNumber(number);        this.setCompScore(compScore);        this.setEngScore(engScore);        this.setMathScore(mathScore);    }        public int sum(        int engScore,        int mathScore,        int compScore) {                int sum = engScore + compScore + mathScore;                System.out.println(sum);        return sum;    }        public String compare(int a, int b) { //你可以在main里面分别调用sum(....);分别得到总数,然后再调用此方法!        if(a > b) {            return "大于";        } else if(a < b) {            return "小于";        } else {            return "等于";        }    }        public int testScore(            int engScore,            int mathScore,            int compScore) {                int sum = this.sum(engScore, mathScore, compScore);                return sum/3;            }}
  相关解决方案