用java解答
1定义一个员工类,内有姓名与年龄,有一个抽象方法计算其总薪水,有个私有静态属性参数统计创建了多少个员工类对象,有个公有方法获取员工类对象个数,有个构造函数初始化参数,并累加个数。
2.定义一个运动类继承了员工类也继承该接口,运动员类有基本薪水与职位薪水属性,其总薪水为基本薪水加职位薪水,如果总薪水不在3000至70000之间则抛出一个Exception异常;如果年龄大于45则表示要退役即退休,如果年龄大于130,抛出一个自定义异常,还有2个构造函数。
3.再定义一个销售员类,他继承了员工类,销售员类有个属性销售数量,其销售数量乘100再加800作为其总薪水,如果总薪水小于800,抛出一个Exception异常;如果年龄大于65则表示退休,还有2个构造函数。
用java解答1.定义一个员工类,内有姓名与年龄,有一个抽象方法计算其总薪水,
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- 不可描述的两脚兽 2022-09-08 11:36关注
import java.util.LinkedList; import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; public abstract class Employee { private String name; private int age; private static List<Employee> employees = new LinkedList<>(); abstract int salary() throws Exception; public Employee(String name, int age){ this.name = name; this.age = age; employees.add(this); } public String getName() { return name; } public int getAge() { return age; } } class Player extends Employee{ private int baseSalary; private int jobSalary; public Player (String name, int age, int baseSalary, int jobSalary) { super(name, age); this.baseSalary = baseSalary; this.jobSalary = jobSalary; } @Override public int salary() throws Exception { int sal = baseSalary + jobSalary; if(!(3000<sal && sal<70000)){ throw new Exception("salary is not between 3000 and 70000."); } return 0; } public boolean isRetire() throws AgeException { int age = super.getAge(); if(age>130){ throw new AgeException(age); } return age > 45; } } class Salesman extends Employee{ private int salesCount; public Salesman(String name, int age) { super(name, age); } public Salesman(String name,int age, int salesCount){ super(name,age); this.salesCount = salesCount; } @Override int salary() throws Exception { int sal = salesCount*100+800; if(sal<800){ throw new Exception("salary less than 800."); } return sal; } public boolean isRetire(){ int age = super.getAge(); return age > 65; } } class AgeException extends Exception{ private int age; public AgeException(int age){ super("Wrong Age Exception: " + age); this.age = age; } public AgeException(int age, String errMsg){ super(errMsg); this.age = age; } public int getAge() { return age; } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
- ¥15 这种微信登录授权 谁可以做啊
- ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
- ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
- ¥15 网络设备配置与管理这个该怎么弄
- ¥20 机器学习能否像多层线性模型一样处理嵌套数据
- ¥20 西门子S7-Graph,S7-300,梯形图
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!