当前位置: 首页 > 工具软件 > doctor > 使用案例 >

创建一个Doctor类,姓名,有suggest方法和operation方法:输出“注意复诊”,“正在检查”,创建一个中医类,继承Doctor,创建一个西医类,继承Doctor.....

微生宝
2023-12-01
package exam3;

/**
	编写一个Java应用程序,创建对应的类,并完成以下程序功能:
	(1)	创建一个Doctor类,姓名,有suggest方法和operation方法:输出“注意复诊”,“正在检查”
	(2)	创建一个中医类,继承Doctor,重写suggest和operation方法输出“注意休息”,“望闻问切” 
	(3)	创建一个西医类,继承Doctor,重写重写suggest和operation方法输出“多锻炼”,“做个CT”
	(4)	创建一个Test类,分别实例化三个医生,并测试 suggest和operation方法
	
	
	1.	正确创建各个类并重写父类方法(5分)
	2.	正确完成带参构造函数编写(5分)
	3.	正确定义父类带参函数构造的实例化对象(10分)
	4.	正确完成完成功能调用(5分)
 */
public class Test {
	public static void main(String[] args) {
		Doctor doctor = new Doctor("医生");
		doctor.suggest();
		doctor.operation();
		Doctor zhDoctor = new ZhDoctor("中医");
		zhDoctor.suggest();
		zhDoctor.operation();
		Doctor westDoctor = new WestDoctor("西医");
		westDoctor.suggest();
		westDoctor.operation();

	}
}

package exam3;

public class Doctor {
	// 创建一个Doctor类,姓名,有suggest方法和operation方法:输出“注意复诊”,“正在检查”
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Doctor(String name) {
		this.name = name;
	}

	public void suggest() {
		System.out.println(this.getName() + ":注意复诊");
	}

	public void operation() {
		System.out.println(this.getName() + ":正在检查");
	}

}

package exam3;

public class ZhDoctor extends Doctor {

	public ZhDoctor(String name) {
		super(name);
	}

	@Override
	public void suggest() {
		System.out.println(this.getName() + ":注意休息");
	}

	@Override
	public void operation() {
		System.out.println(this.getName() + ":望闻问切");
	}
}

package exam3;

public class WestDoctor extends Doctor {

	public WestDoctor(String name) {
		super(name);
	}

	@Override
	public void suggest() {
		System.out.println(this.getName() + ":多锻炼");
	}

	@Override
	public void operation() {
		System.out.println(this.getName() + ":做个CT");
	}

}

/* 
运行:

医生:注意复诊
医生:正在检查
中医:注意休息
中医:望闻问切
西医:多锻炼
西医:做个CT
 */

 类似资料: