接口Java实验代码
作者:互联网
在学校中,学生每个月需要交相应的生活费,老师每个月有相应的工资,而在职研究生既是老师又是学生,所以在职研究生既需要交学费又会有工资。下面要求编写一个程序来统计在职研究生的收入与学费,如果收入无法满足交学费,则输出“撸起袖子加油干!”信息。
package practice;
public class Demo02 {
public static void main(String[] args) {
Graduate gr=new Graduate("张三","男",18,2000,2900);
judge(gr);
}
public static void judge(Graduate gr) {
if(gr.getPay()-gr.getFee()<1000) {
System.out.println("撸起袖子加油干");
}else {
System.out.println("衣食无忧");
}
}
}
interface Teacher{
public void setPay(double pay);
public double getPay();
}
interface Student{
public void setFee(double fee);
public double getFee();
}
class Graduate implements Student,Teacher{
String name;
String gender;
int age;
double fee;
double pay;
//无参构造
public Graduate() {}
//构造方法
public Graduate(String name,String gender,int age,double fee,double pay) {
this.name=name;
this.gender=gender;
this.age=age;
this.fee=fee;
this.pay=pay;
}
@Override
public void setPay(double pay) {
this.pay=pay;
}
@Override
public double getPay() {
return this.pay;
}
@Override
public void setFee(double fee) {
this.fee=fee;
}
@Override
public double getFee() {
return this.fee;
}
}
标签:fee,Java,double,代码,接口,Graduate,void,pay,public 来源: https://blog.csdn.net/m0_56698045/article/details/121058465