- 员工类:
- 属性:姓名,年龄,工资
方法:工作
经理类:多加了奖金,工作的方法打印”管理酒店”
- 服务员类:工作方式打印“上菜和结账”
厨师类:工作方法打印“做饭”
一共有一个经理,2个服务员,一个初始(自己定义属性)
- 所有的员工都需要工作
- 求所有的员工的工资总收入是多少
父类:用来定义属性
package Test12_Demo.Demo09;/*
@create 2020--11--30--16:19
*/
public class Attribute {
private String name;
private int age;
private int salary;
public Attribute() {
}
public Attribute(String name, int age, int salary) {
this.name = name;
this.age = age;
this.salary = salary;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public void work(){
System.out.println("work work");
}
}
厨师类:
package Test12_Demo.Demo09;/*
@create 2020--11--30--16:21
*/
public class Cooker extends Attribute {
public void work() {
System.out.println("厨师正在做饭");
}
public Cooker() {
}
public Cooker(String name, int age, int salary) {
super(name, age, salary);
}
}
经理类:
package Test12_Demo.Demo09;/*
@create 2020--11--30--16:21
*/
public class Manager extends Attribute{
private int bonus;
public void work() {
System.out.println("经历在管理酒店");
}
public Manager() {
}
public Manager(int bonus) {
this.bonus = bonus;
}
public Manager(String name, int age, int salary, int bonus) {
super(name, age, salary);
this.bonus = bonus;
}
public int getBonus() {
return bonus;
}
public void setBonus(int bonus) {
this.bonus = bonus;
}
}
服务员类:
package Test12_Demo.Demo09;/*
@create 2020--11--30--16:22
*/
import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
import org.w3c.dom.ls.LSOutput;
public class StaffOne extends Attribute {
public void work() {
System.out.println("服务员一在上菜和结账");
}
public StaffOne() {
}
public StaffOne(String name, int age, int salary) {
super(name, age, salary);
}
}
package Test12_Demo.Demo09;/*
@create 2020--11--30--16:22
*/
public class StaffTwo extends Attribute {
public void work() {
System.out.println("服务员二在上菜和结账");
}
public StaffTwo() {
}
public StaffTwo(String name, int age, int salary) {
super(name, age, salary);
}
}
测试类:
/**
*
* 员工类:
* 属性:姓名,年龄,工资
* 方法:工作
*
* 经理类:多加了奖金,工作的方法打印"管理酒店"
* 服务员类:工作方式打印“上菜和结账”
* 厨师类:工作方法打印“做饭”
*
* 一共有一个经理,2个服务员,一个初始(自己定义属性)
* 所有的员工都需要工作
* 求所有的员工的工资总收入是多少
*
*/
package Test12_Demo.Demo09;/*
@create 2020--11--30--16:06
*/
import sun.security.krb5.internal.crypto.CksumType;
public class DemoTest {
public static void main(String[] args) {
Cooker cooker = new Cooker("Cooker",20,3000);
System.out.println("厨师的姓名为:"+cooker.getName()+",年龄为:" + cooker.getAge()+",工资为:"+cooker.getSalary());
Manager manager = new Manager("Manager", 20, 3000,2000);
System.out.println("经理的姓名为:"+manager.getName()+",年龄为:" + manager.getAge()+",工资为:"+manager.getSalary()+"奖金为:"+manager.getBonus());
StaffOne staffOne = new StaffOne("StaffOne", 20, 1500);
System.out.println("第一个服务员的姓名为:"+staffOne.getName()+",年龄为:" + staffOne.getAge()+",工资为:"+staffOne.getSalary());
StaffTwo staffTwo = new StaffTwo("StaffTwo", 20, 1500);
System.out.println("第二个服务员的姓名为:"+staffTwo.getName()+",年龄为:" + staffTwo.getAge()+",工资为:"+staffTwo.getSalary());
work(cooker, manager, staffOne, staffTwo);
int sum = getSum(cooker, manager, staffOne, staffTwo);
System.out.println("工资之和为:" + sum);
}
public static void work(Cooker cooker, Manager manager, StaffOne staffOne, StaffTwo staffTwo) {
cooker.work();
manager.work();
staffOne.work();
staffTwo.work();
}
public static int getSum(Cooker cooker, Manager manager, StaffOne staffOne, StaffTwo staffTwo) {
return cooker.getSalary() + manager.getBonus() + manager.getSalary() + staffOne.getSalary() + staffTwo.getSalary();
}
}