程序实现的功能:
1.定义一个学生类(student),成员变量:id(学号),name(姓名),fee(学费/年),成员方法:获取学费 getFee();
2.定义一个在职研究生类(Graduate),它继承自学生类,成员变量:pay(工资/月),成员方法:获取工 资getPay();
3.创建一个Graduate类的对象,统计他的年收入,如果年收入减去学费不足12000元,则输出“you need a loan”(需要贷款),否则输出“your pay is enough!”。
class Student{
String id;
String name;
int fee;
public Student(String id,String name,int fee) {
this.id=id;
this.name=name;
this.fee=fee;
}
public int getFee() {
return fee;
}
}
class Graduate extends Student{
int pay;
public Graduate(String id,String name,int fee,int pay) {
super(id,name,fee);
this.pay=pay;
}
public int getPay() {
return pay;
}
public void speak() {
if(12*getPay()-getFee()<12000)
System.out.println("you need a loan");
else
System.out.println("your pay is enough!");
}
}
public class Test3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Graduate g1=new Graduate("0528","lpt",100000,1000);
g1.speak();
}
}