JAVA中的stu什么意思_JAVA编程作业完成下面父类和子类的定义:(1)定义Student类,放入stu包中。属性包括学号、姓名、英语成绩、数学...

共回答了19个问题采纳率:78.9%

网上找的,你试试能用吗

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());

}

}

1年前

2

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值