• 员工类:
    • 属性:姓名,年龄,工资
    • 方法:工作

    • 经理类:多加了奖金,工作的方法打印”管理酒店”

    • 服务员类:工作方式打印“上菜和结账”
    • 厨师类:工作方法打印“做饭”

    • 一共有一个经理,2个服务员,一个初始(自己定义属性)

    • 所有的员工都需要工作
    • 求所有的员工的工资总收入是多少

    父类:用来定义属性

    1. package Test12_Demo.Demo09;/*
    2. @create 2020--11--30--16:19
    3. */
    4. public class Attribute {
    5. private String name;
    6. private int age;
    7. private int salary;
    8. public Attribute() {
    9. }
    10. public Attribute(String name, int age, int salary) {
    11. this.name = name;
    12. this.age = age;
    13. this.salary = salary;
    14. }
    15. public String getName() {
    16. return name;
    17. }
    18. public void setName(String name) {
    19. this.name = name;
    20. }
    21. public int getAge() {
    22. return age;
    23. }
    24. public void setAge(int age) {
    25. this.age = age;
    26. }
    27. public int getSalary() {
    28. return salary;
    29. }
    30. public void setSalary(int salary) {
    31. this.salary = salary;
    32. }
    33. public void work(){
    34. System.out.println("work work");
    35. }
    36. }

    厨师类:

    1. package Test12_Demo.Demo09;/*
    2. @create 2020--11--30--16:21
    3. */
    4. public class Cooker extends Attribute {
    5. public void work() {
    6. System.out.println("厨师正在做饭");
    7. }
    8. public Cooker() {
    9. }
    10. public Cooker(String name, int age, int salary) {
    11. super(name, age, salary);
    12. }
    13. }

    经理类:

    1. package Test12_Demo.Demo09;/*
    2. @create 2020--11--30--16:21
    3. */
    4. public class Manager extends Attribute{
    5. private int bonus;
    6. public void work() {
    7. System.out.println("经历在管理酒店");
    8. }
    9. public Manager() {
    10. }
    11. public Manager(int bonus) {
    12. this.bonus = bonus;
    13. }
    14. public Manager(String name, int age, int salary, int bonus) {
    15. super(name, age, salary);
    16. this.bonus = bonus;
    17. }
    18. public int getBonus() {
    19. return bonus;
    20. }
    21. public void setBonus(int bonus) {
    22. this.bonus = bonus;
    23. }
    24. }

    服务员类:

    1. package Test12_Demo.Demo09;/*
    2. @create 2020--11--30--16:22
    3. */
    4. import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
    5. import org.w3c.dom.ls.LSOutput;
    6. public class StaffOne extends Attribute {
    7. public void work() {
    8. System.out.println("服务员一在上菜和结账");
    9. }
    10. public StaffOne() {
    11. }
    12. public StaffOne(String name, int age, int salary) {
    13. super(name, age, salary);
    14. }
    15. }
    1. package Test12_Demo.Demo09;/*
    2. @create 2020--11--30--16:22
    3. */
    4. public class StaffTwo extends Attribute {
    5. public void work() {
    6. System.out.println("服务员二在上菜和结账");
    7. }
    8. public StaffTwo() {
    9. }
    10. public StaffTwo(String name, int age, int salary) {
    11. super(name, age, salary);
    12. }
    13. }

    测试类:

    1. /**
    2. *
    3. * 员工类:
    4. * 属性:姓名,年龄,工资
    5. * 方法:工作
    6. *
    7. * 经理类:多加了奖金,工作的方法打印"管理酒店"
    8. * 服务员类:工作方式打印“上菜和结账”
    9. * 厨师类:工作方法打印“做饭”
    10. *
    11. * 一共有一个经理,2个服务员,一个初始(自己定义属性)
    12. * 所有的员工都需要工作
    13. * 求所有的员工的工资总收入是多少
    14. *
    15. */
    16. package Test12_Demo.Demo09;/*
    17. @create 2020--11--30--16:06
    18. */
    19. import sun.security.krb5.internal.crypto.CksumType;
    20. public class DemoTest {
    21. public static void main(String[] args) {
    22. Cooker cooker = new Cooker("Cooker",20,3000);
    23. System.out.println("厨师的姓名为:"+cooker.getName()+",年龄为:" + cooker.getAge()+",工资为:"+cooker.getSalary());
    24. Manager manager = new Manager("Manager", 20, 3000,2000);
    25. System.out.println("经理的姓名为:"+manager.getName()+",年龄为:" + manager.getAge()+",工资为:"+manager.getSalary()+"奖金为:"+manager.getBonus());
    26. StaffOne staffOne = new StaffOne("StaffOne", 20, 1500);
    27. System.out.println("第一个服务员的姓名为:"+staffOne.getName()+",年龄为:" + staffOne.getAge()+",工资为:"+staffOne.getSalary());
    28. StaffTwo staffTwo = new StaffTwo("StaffTwo", 20, 1500);
    29. System.out.println("第二个服务员的姓名为:"+staffTwo.getName()+",年龄为:" + staffTwo.getAge()+",工资为:"+staffTwo.getSalary());
    30. work(cooker, manager, staffOne, staffTwo);
    31. int sum = getSum(cooker, manager, staffOne, staffTwo);
    32. System.out.println("工资之和为:" + sum);
    33. }
    34. public static void work(Cooker cooker, Manager manager, StaffOne staffOne, StaffTwo staffTwo) {
    35. cooker.work();
    36. manager.work();
    37. staffOne.work();
    38. staffTwo.work();
    39. }
    40. public static int getSum(Cooker cooker, Manager manager, StaffOne staffOne, StaffTwo staffTwo) {
    41. return cooker.getSalary() + manager.getBonus() + manager.getSalary() + staffOne.getSalary() + staffTwo.getSalary();
    42. }
    43. }