早教吧作业答案频道 -->其他-->
JAVA编程作业完成下面父类和子类的定义:(1)定义Student类,放入stu包中。属性包括学号、姓名、英语成绩、数学成绩、计算机成绩和总成绩。方法包括构造方法、get方法、set方法、toString
题目详情
JAVA编程作业
完成下面父类和子类的定义:
(1)定义Student类,放入stu包中。
属性包括学号、姓名、英语成绩、数学成绩、计算机成绩和总成绩。
方法包括构造方法、get方法、set方法、toString方法(返回该类的对象)、equals方法(比较两个对象是否相等,若等返回true,否则返回false)、compare方法(比较两个学生的总成绩,结果分为大于、小于、等于)、sum方法(计算总成绩)、testScore方法(计算评测成绩)。
注:评测成绩可以取三门课成绩的平均分,另外任何一门课的成绩的改变都需要对总成绩进行重新计算,因此在每一个set方法中应调用sum方法计算总成绩。
(2)定义StudentXW类为Student的子类,放入sub包中。
在StudentXW(学习委员)类中增加责任属性,并重写testScore方法(计算测评成绩,测评成绩=三门课的平均分+3)。
(3)定义StudentBZ(班长)类为Student的子类,放入sub包中。
在StudentXW(学习委员)类中增加责任属性,并重写testScore方法(计算测评成绩,测评成绩=三门课的平均分+5)。
(4)定义测试类,生成若干个Student类、StudentXW类及StudentXW类的对象,并分别计算它们的评测成绩。
完成下面父类和子类的定义:
(1)定义Student类,放入stu包中。
属性包括学号、姓名、英语成绩、数学成绩、计算机成绩和总成绩。
方法包括构造方法、get方法、set方法、toString方法(返回该类的对象)、equals方法(比较两个对象是否相等,若等返回true,否则返回false)、compare方法(比较两个学生的总成绩,结果分为大于、小于、等于)、sum方法(计算总成绩)、testScore方法(计算评测成绩)。
注:评测成绩可以取三门课成绩的平均分,另外任何一门课的成绩的改变都需要对总成绩进行重新计算,因此在每一个set方法中应调用sum方法计算总成绩。
(2)定义StudentXW类为Student的子类,放入sub包中。
在StudentXW(学习委员)类中增加责任属性,并重写testScore方法(计算测评成绩,测评成绩=三门课的平均分+3)。
(3)定义StudentBZ(班长)类为Student的子类,放入sub包中。
在StudentXW(学习委员)类中增加责任属性,并重写testScore方法(计算测评成绩,测评成绩=三门课的平均分+5)。
(4)定义测试类,生成若干个Student类、StudentXW类及StudentXW类的对象,并分别计算它们的评测成绩。
▼优质解答
答案和解析
网上找的,你试试能用吗
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());
}
}
看了 JAVA编程作业完成下面父类...的网友还看了以下:
闭合电路中,错误的是:A.U内=Ir B.U外=Ir C.U外=ER/(R+r) D.U内=Er闭 2020-05-16 …
设Φ(u,v)具有连续偏导数,证明由方程Φ(cx-az,cy-bz)=0所确定的函数z=f(x,y 2020-05-17 …
定义全集U的子集A的特征函数为fA(x)=1,x∈A0,x∈CUA,这里∁UA表示集合A在全集U中 2020-05-24 …
已知全集为U,P?U,定义集合P的特征函数为,对于A?U,B?U,给出下列四个结论:①对?x∈U, 2020-05-24 …
求最大值cos(a)/u+sin(a)cos(a)/u+sin(a)a=?时有最大值?0尤其是构造 2020-06-03 …
给定全集∪,若非空集合A、B满足A⊆U,B⊆U且集合A中的最大元素小于B中的最小元素,则称(A,B 2020-07-10 …
关于两个小球相撞的问题小球A和B的质量相同,B球原来静止,A以速度u与B作对心碰撞.这两球碰撞后的 2020-07-18 …
设全集U={1234567}集合A={1357}集合B={35}则()A.U=A∪BB.U=(A) 2020-07-30 …
绩效管理试题,求解答1.关键事件法的缺点是()A.无法为考评者提供客观依据B.不能做定量分析C.不能 2020-11-06 …
a:A交B=U(全集)b:A=U或B=Ua是b的充分非必要条件把b改成A=U且B=U那是充要吗?a: 2021-01-04 …