1、编写一个程序,该程序由一个主程序、一个接口和2个类组成。
1)Student类
有姓名、学号、班级3个成员,构造方法对3个成员赋值,一个方法输出成员的值,一个方法比较2个Student对象的姓名、学号、班级是否一致。
2)接口
有一个抽象方法,用于判断学生是否符合获得奖学金的条件。
3)UniversityStudent类
继承自Student类并实现了接口,新增绩点、平均分2个成员。构造方法对所有成员赋值;一个方法输出所有成员的值。
4)主程序main方法
创建2个Student对象,分别输出他们的姓名、学号、班级等信息;根据这些信息判断是否为同一个人。
创建1个UniversityStudent对象,要求输出对象的姓名、学号、班级、绩点、平均分等信息;
如有帮助望采纳。点击我回答右上角的【采纳】按钮。
public class Student {
private String name;
private String sno;
private String classname;
public Student(){}
public Student(String name, String sno, String classname) {
this.name = name;
this.sno = sno;
this.classname = classname;
}
public String show(){
return "姓名:"+name+",学号:"+sno+",班级:"+classname;
}
public boolean isMyself(Student stu){
if (this.name.equals(stu.name)&&this.sno.equals(stu.sno)&&this.classname.equals(stu.classname)){
return true;
}
return false;
}
}
public interface Scholarship {
public abstract boolean isShip();
}
public class UniversityStudent extends Student implements Scholarship{
private int spot;
private double avg;
public UniversityStudent(String name, String sno, String classname, int spot, double avg) {
super(name, sno, classname);
this.spot = spot;
this.avg = avg;
}
@Override
public boolean isShip() {
if (this.avg>95 && spot>9){
return true;
}
return false;
}
public String show(){
return super.show()+",绩点:"+this.spot+",平均分:"+this.avg;
}
}
public class Test {
public static void main(String[] args) {
Student s1=new Student("小白","1001","计算机");
Student s2=new Student("小白","1001","计算机");
boolean flag=s1.isMyself(s2);
if (flag){
System.out.println("是同一个人");
}else{
System.out.println("不是同一个人");
}
UniversityStudent uStudent=new UniversityStudent("小黑","10002","通信",10,98.5);
System.out.println(uStudent.show());
}
}
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632