早教吧作业答案频道 -->其他-->
2.完成下面父类及子类的声明(1)声明Student类属性包括学号、姓名、英语成绩、数学成绩、计算机成绩和总2.完成下面父类及子类的声明(1)声明Student类属性包括学号、姓名、英语成绩、数学
题目详情
2.完成下面父类及子类的声明 (1) 声明Student类属性包括学号、姓名、英语成绩、数学成绩、计算机成绩和总
2.完成下面父类及子类的声明
(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数组作为参数) .
2.完成下面父类及子类的声明
(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数组作为参数) .
▼优质解答
答案和解析
写好了给你了
public class Student implements Comparable{
public Student(String no, String name) {
this.no = no;
this.name = name;
}
public Student() {
}
public Student(String no, String name, double english, double maths,
double computer, double sum) {
this.no = no;
this.name = name;
this.english = english;
this.maths = maths;
this.computer = computer;
this.sum = sum;
}
private String no;
private String name;
private double english;
private double maths;
private double computer;
private Double sum=0.0;
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getEnglish() {
return english;
}
public void setEnglish(double english) {
this.english = english;
sum+=english;
}
public double getMaths() {
return maths;
}
public void setMaths(double maths) {
this.maths = maths;
sum+=maths;
}
public double getComputer() {
return computer;
}
public void setComputer(double computer) {
this.computer = computer;
sum+=computer;
}
public Double getSum() {
return sum;
}
public void setSum(Double sum) {
this.sum = sum;
}
public String toString() {
return "学号:"+no+"姓名"+name+"英语"+english+"数学"+maths+"计算机"+computer+"总成绩"+sum;
}
public int compareTo(Object o) {
return sum.compareTo(((Student)o).getSum());
}
public Double sum(){
return english+maths+computer;
}
public Double testScore(){
return sum/3;
}
}
public class StudentXW extends Student{
public StudentXW(String no, String name) {
super(no,name);
}
public StudentXW() {
super();
}
private String duty;
public String getDuty() {
return duty;
}
public void setDuty(String duty) {
this.duty = duty;
}
public Double testScore() {
return super.testScore()+3;
}
}
public class StudentBZ extends Student{
public StudentBZ(String no, String name) {
super(no,name);
}
public StudentBZ() {
super();
}
private String duty;
public String getDuty() {
return duty;
}
public void setDuty(String duty) {
this.duty = duty;
}
public Double testScore() {
return super.testScore()+5;
}
}
public class Test {
public static void main(String[] args) {
Student student1=new Student("001","1");
student1.setEnglish(60.0);
student1.setMaths(60.0);
student1.setComputer(60.0);
System.out.println(student1+"测试成绩是"+student1.testScore());
Student student2=new StudentXW("002","2");
student2.setEnglish(70.0);
student2.setMaths(70.0);
student2.setComputer(70.0);
System.out.println(student2+"测试成绩是"+student2.testScore());
Student student3=new StudentBZ("003","3");
student3.setEnglish(80.0);
student3.setMaths(80.0);
student3.setComputer(80.0);
System.out.println(student3+"测试成绩是"+student3.testScore());
}
}
public class Student implements Comparable{
public Student(String no, String name) {
this.no = no;
this.name = name;
}
public Student() {
}
public Student(String no, String name, double english, double maths,
double computer, double sum) {
this.no = no;
this.name = name;
this.english = english;
this.maths = maths;
this.computer = computer;
this.sum = sum;
}
private String no;
private String name;
private double english;
private double maths;
private double computer;
private Double sum=0.0;
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getEnglish() {
return english;
}
public void setEnglish(double english) {
this.english = english;
sum+=english;
}
public double getMaths() {
return maths;
}
public void setMaths(double maths) {
this.maths = maths;
sum+=maths;
}
public double getComputer() {
return computer;
}
public void setComputer(double computer) {
this.computer = computer;
sum+=computer;
}
public Double getSum() {
return sum;
}
public void setSum(Double sum) {
this.sum = sum;
}
public String toString() {
return "学号:"+no+"姓名"+name+"英语"+english+"数学"+maths+"计算机"+computer+"总成绩"+sum;
}
public int compareTo(Object o) {
return sum.compareTo(((Student)o).getSum());
}
public Double sum(){
return english+maths+computer;
}
public Double testScore(){
return sum/3;
}
}
public class StudentXW extends Student{
public StudentXW(String no, String name) {
super(no,name);
}
public StudentXW() {
super();
}
private String duty;
public String getDuty() {
return duty;
}
public void setDuty(String duty) {
this.duty = duty;
}
public Double testScore() {
return super.testScore()+3;
}
}
public class StudentBZ extends Student{
public StudentBZ(String no, String name) {
super(no,name);
}
public StudentBZ() {
super();
}
private String duty;
public String getDuty() {
return duty;
}
public void setDuty(String duty) {
this.duty = duty;
}
public Double testScore() {
return super.testScore()+5;
}
}
public class Test {
public static void main(String[] args) {
Student student1=new Student("001","1");
student1.setEnglish(60.0);
student1.setMaths(60.0);
student1.setComputer(60.0);
System.out.println(student1+"测试成绩是"+student1.testScore());
Student student2=new StudentXW("002","2");
student2.setEnglish(70.0);
student2.setMaths(70.0);
student2.setComputer(70.0);
System.out.println(student2+"测试成绩是"+student2.testScore());
Student student3=new StudentBZ("003","3");
student3.setEnglish(80.0);
student3.setMaths(80.0);
student3.setComputer(80.0);
System.out.println(student3+"测试成绩是"+student3.testScore());
}
}
看了 2.完成下面父类及子类的声明...的网友还看了以下:
下列说法正确的是A.整数包括正整数、负整数B.分数包括正分数、负分数和0C.有理数中不是负数就是正 2020-05-13 …
证明A*B集合可数假设ABCD为集合,A包含于C,且B包含于D.如果C*D是可数的,证明A*B也是 2020-05-15 …
二级Access如有数组声明语句Dima(2,-3to2,4),则数组a包含元素的个数是()。A) 2020-05-17 …
A.透明的网桥B.半透明的网桥C.转换协议的网桥D.改变数据包封装的网桥 2020-05-26 …
函数的概念问题高等数学里面,函数的定义是:设集数D包含于R,则称映射f:D→R为定义在D上的函数… 2020-06-08 …
向量数量积分配律证明向量数量积分配律a•(b+c)=a•b+a•c,(a+b)•(c+d)=a•c 2020-06-19 …
数学概率之独立事件已知A与B独立,C包含于B,而D包含于A,还有E也包含于A.下面问:1、A与C是 2020-07-30 …
多选题3.发盘内容至少应包括的基本要素是()A.标明货物的名称B.明示或默示地规定货物的数量C.明示 2020-11-23 …
数据库:关系模式R(A,B,C,D,E)...函数依赖F={A-D,E-D,D-B,BC-D,CD- 2020-12-08 …
下列词语中加横线的字读音完全相同的一组是()A.腈纶粳米菁华泾渭分明数茎华发B.跂望契合修葺迄今为止 2020-12-24 …