compilation error the constructor of a class can not be applied to given types

I believe the answer you are looking for is very simple. If you invoke the parent constructor to the subclass, this should resolve the compilation problems. You can do this by using the following changes. The change I made is at the beginning of the constructor, it simply calls the parents constructor to create an object, since it is a subclass.

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){
    enter code here

        super(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(){
        //

}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top