用java定义一个研究生类Graduate,实现StudentInterface和TeacherInterface接口,它的成员变量有name(姓名)、set(性别)、age(年龄)、fee(每学期学费)、pay(月工资)。
时间: 2023-07-10 19:17:06 浏览: 63
好的,根据您的要求,我可以编写一个简单的Java代码来实现这个问题的解决方案。请参考下面的代码:
```java
// 定义研究生类
public class Graduate implements StudentInterface, TeacherInterface {
private String name;
private String sex;
private int age;
private double fee;
private double pay;
// 构造函数
public Graduate(String name, String sex, int age, double fee, double pay) {
this.name = name;
this.sex = sex;
this.age = age;
this.fee = fee;
this.pay = pay;
}
// 实现StudentInterface接口中的方法
public double getFee() {
return fee;
}
// 实现TeacherInterface接口中的方法
public double getPay() {
return pay;
}
// 实现接口中的方法
public String getName() {
return name;
}
public String getSex() {
return sex;
}
public int getAge() {
return age;
}
public void setName(String name) {
this.name = name;
}
public void setSex(String sex) {
this.sex = sex;
}
public void setAge(int age) {
this.age = age;
}
public void setFee(double fee) {
this.fee = fee;
}
public void setPay(double pay) {
this.pay = pay;
}
}
```
在上面的代码中,我们定义了一个 Graduate 类,它实现了 StudentInterface 和 TeacherInterface 接口。该类有五个成员变量:name、sex、age、fee 和 pay。我们在构造函数中初始化了这些成员变量,并实现了接口中的方法。其中,getFee() 方法用于获取每学期学费,getPay() 方法用于获取月工资,getName()、getSex() 和 getAge() 方法用于获取姓名、性别和年龄,setFee() 和 setPay() 方法用于设置每学期学费和月工资,setName()、setSex() 和 setAge() 方法用于设置姓名、性别和年龄。
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)