编译错误:类中的构造函数无法应用于给定类型

问题描述

我试图使用超类中的枚举创建子类对象,但是当我尝试在子类中创建对象时,出现此错误。

error: constructor Payroll in class Payroll cannot be applied to given types;
        public PayClaim(int hours,PayLevel level){
                                                  ^
  required: PayLevel
  found:    no arguments
  reason: actual and formal argument lists differ in length
1 error

这是我的超类工资

public class Payroll{
    
    
    static double OVERTIME_RATE = 1.5;

    static int REGULAR_WEEK = 40;
    static int LEVEL_ONE_PAY = 15;
    static int LEVEL_TWO_PAY = 25;
    static int LEVEL_THREE_PAY = 40;
    
    public enum PayLevel{
        ONE,TWO,THREE
    }
    
    private PayLevel levels;
    public Payroll(PayLevel levels){
        this.levels = levels;
    }
    
    public PayLevel getPayLevel(){
        return levels;
    }
    
    public static void main (String [] args) {
        Payroll.OVERTIME_RATE = 1.75;
        Payroll.REGULAR_WEEK = 40;
        Payroll.LEVEL_ONE_PAY = 12;
        System.out.println(Payroll.calculatePay(35,Payroll.PayLevel.ONE));
    }
    
    public static double calculatePay(int noHoursWorked,PayLevel level){
    //do stuff
    }
    
}

这是我的PayClaim子类

public class PayClaim extends Payroll{
    
    
    int noHoursWorked;
    public Payroll.PayLevel payLevel;
    double calculatedPay = 0;
    
    public static void main (String [] args) {
        PayClaim p = new PayClaim(1,Payroll.PayLevel.ONE);
        System.out.println(p);
    }
    
    public PayClaim(int hours,PayLevel level){
        
        if(hours > 80 || hours < 1){
            throw new IllegalArgumentException();
        }
        else{
            noHoursWorked = hours;
            payLevel = level;
        }
    }
    
    public int getNoHoursWorked(){
        return noHoursWorked;
    }
    
    public PayLevel getPayLevel(){
        return payLevel;
    }
    
    public double getClaculatedPay(){
        return calculatedPay;
    }
    
    public void setCalculatedPay(double pay){
        //
    }
    
    public String toString(){
        //

}

如果我错过了一些琐碎的事情,我很抱歉,只是代码甚至无法编译,所以我真的很努力地找到我要去哪里的地方。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)