java编程问题

2024-11-22 04:44:23
推荐回答(1个)
回答1:

public class Card {

private String num;
private String name;
private String sex;
private String birth;
public String getBirth() {
return birth;
}
public void setBirth(String birth) {
this.birth = birth;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
---------------------------------------
public class TeacherCard extends Card{

private String work;
private String date;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getWork() {
return work;
}
public void setWork(String work) {
this.work = work;
}
}
-----------------------------------------
public class StudentCard {
private String department;
private String time;
private String message;
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}

}
--------------------------------
public abstract class Person {
public abstract double pay();
}
---------------------------------
public class Teacher extends Person implements Pay{

private double basePay;
private double hour;

private TeacherCard teacherCard;
public double pay() {

return this.basePay + this.hour * 30;

}
public double getBasePay() {
return basePay;
}
public void setBasePay(double basePay) {
this.basePay = basePay;
}
public double getHour() {
return hour;
}
public void setHour(double hour) {
this.hour = hour;
}
public TeacherCard getTeacherCard() {
return teacherCard;
}
public void setTeacherCard(TeacherCard teacherCard) {
this.teacherCard = teacherCard;
}
}
----------------------------------
public class CollegeStudent extends Person{

private double outPay;
private StudentCard studentCard;
public double getOutPay() {
return outPay;
}
public void setOutPay(double outPay) {
this.outPay = outPay;
}
public StudentCard getStudentCard() {
return studentCard;
}
public void setStudentCard(StudentCard studentCard) {
this.studentCard = studentCard;
}
public double pay() {
return outPay;

}
}
------------------------------
public interface Pay {

public double pay();
}
-----------------------------
public class Test {
public static void main(String[] args) {
Person pp = new Teacher();
((Teacher) pp).setBasePay(2000);
((Teacher) pp).setHour(3);
System.out.println(pp.pay());

pp = new CollegeStudent();
((CollegeStudent) pp).setOutPay(500);
System.out.println(pp.pay());
}
}

//一共8个类,我测试过了,不懂问我~