Java写一个接口和两个类

编写一个接口和两个类,要求如下:
(1)设计一个学生功能的接口,实现平均成绩的计算和基本信息的输出。
(2)设计一个学生类实现了学生接口,学生类的基本信息有:学号、姓名、年龄、各科成绩(假设一共5门课程,请用数组实现)。
(3)设计一个大学生类继承了学生类:
大学生除了包含普通学生的信息外,还包包含:德育成绩、体育成绩、美育成绩;以及一个能够算综合排名成绩的成员方法(假设综合排名成绩=德育成绩+体育成绩+美育成绩+平均成绩)

最后编写一个main方法测试上面的两个类。

//接口 IStudent.java

public interface IStudent {
public double avgScore();
public void outputInfo();
}

//类Student

public class Student implements IStudent {
private String sno;
private String name;
private int age;
public double[] scores;
public Student(String sno,String name,int age,double []score){
this.name = name;
this.scores= score;
this.age = age;
this.sno = sno;
}
public double avgScore() {
double total= 0;
for(int i=0,len=scores.length;i<len;i++){
total += scores[i];
}
return total;
}

public void outputInfo() {
System.out.println("学号 "+sno+" 姓名 "+name +"年龄 "+age);
}

}
//类 CollegeStudent大学生

public class CollegeStudent extends Student {
private double dy;
private double ty;
private double my;
public CollegeStudent(String sno,String name,int age,double [] score,double dy,double ty,double my){
super(sno, name, age, score);
this.dy = dy;
this.ty = ty;
this.my = my;
}
public double calScore(){
return avgScore()+dy+ty+my;
}
public static void main(String []args){
double []score = {100,100,100,100,100};
CollegeStudent collegeStudent = new CollegeStudent("06411100","张三",20,score,100.0,100.0,100.0);
collegeStudent.outputInfo();
System.out.println("平均成绩 "+collegeStudent.avgScore());
System.out.println("综合成绩 "+collegeStudent.calScore());
}
}

//


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值