class Test3_Employee {
public static void main(String[] args) {
Coder c = new Coder("德玛西亚","007",8000.9);
c.work();
Manager m = new Manager("苍老师","001",10000,20000);
m.work();
}
}
/*
假如我们在开发一个系统时需要对程序员类进行设计,程序员包含3个属性:姓名、工号以及工资。
经理,除了含有程序员的属性外,另为还有一个奖金属性。
请使用继承的思想设计出程序员类和经理类。要求类中提供必要的方法进行属性访问。
*/
abstract class Employee {
private String name;
private String id;
private double salary;
public Employee(){}
public Employee(String name,String id,double salary){
this.name = name;
this.id = id;
this.salary = salary;
}
public void setname(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setId(String id){
this.id = id;
}
public String getId(){
return id;
}
public void setSalary(double salary){
this.salary = salary;
}
public double getSalary(){
return salary;
}
public abstract void work();
}
class Coder extends Employee {
public Coder(){}
public Coder(String name,String id,double salary){
super(name,id,salary);
}
public void work(){
System.out.println("我的姓名是:"+ this.getName() + "我的工号是:"+ this.getId()+"我的工资是:"+ this.getSalary() + "我的工作是敲键盘");
}
}
class Manager extends Employee{
private int bouns;
public Manager(){}
public Manager(String name,String id,double salary,int bouns){
super(name,id,salary);
this.bouns = bouns;
}
public void work(){
System.out.println("我的姓名是:"+ getName() +"我的工号是:" + this.getId() +
"我的工资是:" + this.getSalary() + "我的工作是管理" +
"我的奖金是:"+ bouns);
}
} |
|