用java解答1.定义一个员工类,内有姓名与年龄,有一个抽象方法计算其总薪水,

用java解答
1定义一个员工类,内有姓名与年龄,有一个抽象方法计算其总薪水,有个私有静态属性参数统计创建了多少个员工类对象,有个公有方法获取员工类对象个数,有个构造函数初始化参数,并累加个数。
2.定义一个运动类继承了员工类也继承该接口,运动员类有基本薪水与职位薪水属性,其总薪水为基本薪水加职位薪水,如果总薪水不在3000至70000之间则抛出一个Exception异常;如果年龄大于45则表示要退役即退休,如果年龄大于130,抛出一个自定义异常,还有2个构造函数。
3.再定义一个销售员类,他继承了员工类,销售员类有个属性销售数量,其销售数量乘100再加800作为其总薪水,如果总薪水小于800,抛出一个Exception异常;如果年龄大于65则表示退休,还有2个构造函数。


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;
    }
}

同意楼上的说法。

你说的是思路,我这边给个结构

class 员工{
    String xxx;
    int yyy;
    员工(){

    }

    void xx(){

    }
}

加油,你可以的

参考这个写吧

Java 定义一个 Employee类,定义方法输出Employee的名字,年龄,总收入。编写应用程序使用Employee_爱犯错的小z的博客-CSDN博客 题目:【问题描述】定义一个 Employee类,有名字、年龄、基本收入、分红收入等属性,定义构造方法用来初始化类的这些属性。定义方法输出Employee的名字,年龄,总收入(基本收入和分红收入的和)。编写应用程序使用Employee。【输入形式】请输入员工的名字:请输入员工的年龄:请输入员工的基本收入:请输入员工的分红收入:【输出形式】员工的名字:员工的年龄:员工的总收入(基本收入+分红收入):【输入样例】Please input the employee’s name: Tom https://blog.csdn.net/qq_47446178/article/details/116297506