Zetha
Zetha

Reputation: 1

Getting Error:(20, 44) java: constructor XXX cannot be applied to given types;

getting this error which I don't understand. I have made constructors to the best of my knowledge.

Error:(12, 46) java: constructor FitnessEmployees in class com.company.FitnessEmployees cannot be applied to given types; required: java.lang.String,java.lang.String,int,double,java.lang.String,java.lang.String found: no arguments reason: actual and formal argument lists differ in length

My Class:

package com.company;


public class FitnessEmployees {
    private String Name;
    private String CPR;
    private int Hours;
    private double Salary;
    private String Vacation;
    private String EmployeeType;


    public FitnessEmployees(String name, String CPR, int hours, double salary, String vacation, String employeeType) {
        this.Name = name;
        this.CPR = CPR;
        this.Hours = hours;
        this.Salary = salary;
        this.Vacation = vacation;
        this.EmployeeType = employeeType;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    public String getCPR() {
        return CPR;
    }

    public void setCPR(String CPR) {
        this.CPR = CPR;
    }

    public int getHours() {
        return Hours;
    }

    public void setHours(int hours) {
        Hours = hours;
    }

    public double getSalary() {
        return Salary;
    }

    public void setSalary(double salary) {
        Salary = salary;
    }

    public String getVacation() {
        return Vacation;
    }

    public void setVacation(String vacation) {
        Vacation = vacation;
    }

    public String getEmployeeType() {
        return EmployeeType;
    }

    public void setEmployeeType(String employeeType) {
        EmployeeType = employeeType;
    }

    @Override
    public String toString() {
        return "FitnessEmployees{" +
                "Name='" + Name + '\'' +
                ", CPR='" + CPR + '\'' +
                ", Hours=" + Hours +
                ", Salary=" + Salary +
                ", Vacation=" + Vacation +
                ", EmployeeType='" + EmployeeType + '\'' +
                '}';
    }
}

My Main:

package com.company;

public class FitnessMain {

    public static void main(String[] args) {

        int Salaryadmin = 23000;
        int SalaryInstructor = 456;



        FitnessEmployees FitnessEmployees1 = new FitnessEmployees();
        String Name1 = "Claus";
        String CPR1 = "221175-1011";
        int Hours1 = 37;
        double Salary1 = Salaryadmin;
        String Vacation1 = "5";
        String EmployeeType1 = "Administrative";


        FitnessEmployees ObjectEmployee2 = new FitnessEmployees();
        String Name2 = "Tove";
        String CPR2 = "011080-1014";
        int Hours2 = 20;
        double Salary2 = (SalaryInstructor * Hours2);
        String Vacation2 = " ";
        String EmployeeType2 = "Instructor";

        FitnessEmployees ObjectEmployee3 = new FitnessEmployees();
        String Name3 = "Anna";
        String CPR3 = "011080-1012";
        int Hours3 = 37;
        double Salary3 = Salaryadmin;
        String Vacation3 = "5";
        String EmployeeType3 = "Administrative";

        FitnessEmployees ObjectEmployee4 = new FitnessEmployees();
        String Name4 = "Henning";
        String CPR4 = "011080-1014";
        int Hours4 = 20;
        double Salary4 = (SalaryInstructor * Hours2);
        String Vacation4 = " ";
        String EmployeeType4 = "Instructor";





    }
}

Upvotes: 0

Views: 1602

Answers (2)

Adya
Adya

Reputation: 1112

FitnessEmployees ObjectEmployee1 = new FitnessEmployees();
FitnessEmployees ObjectEmployee2 = new FitnessEmployees();
FitnessEmployees ObjectEmployee3 = new FitnessEmployees();
FitnessEmployees ObjectEmployee4 = new FitnessEmployees();

These objects call the default constructor of your FitnessEmployees class. All you need to do is add default constructor :

public FitnessEmployees {
}

Upvotes: 0

ptk
ptk

Reputation: 105

Just add a default constructor as mentioned in the comments by @BugsForBreakfast

package com.company;


public class FitnessEmployees {
    private String Name;
    private String CPR;
    private int Hours;
    private double Salary;
    private String Vacation;
    private String EmployeeType;


public FitnessEmployees(){
}


    public FitnessEmployees(String name, String CPR, int hours, double salary, String vacation, String employeeType) {
        this.Name = name;
        this.CPR = CPR;
        this.Hours = hours;
        this.Salary = salary;
        this.Vacation = vacation;
        this.EmployeeType = employeeType;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    public String getCPR() {
        return CPR;
    }

    public void setCPR(String CPR) {
        this.CPR = CPR;
    }

    public int getHours() {
        return Hours;
    }

    public void setHours(int hours) {
        Hours = hours;
    }

    public double getSalary() {
        return Salary;
    }

    public void setSalary(double salary) {
        Salary = salary;
    }

    public String getVacation() {
        return Vacation;
    }

    public void setVacation(String vacation) {
        Vacation = vacation;
    }

    public String getEmployeeType() {
        return EmployeeType;
    }

    public void setEmployeeType(String employeeType) {
        EmployeeType = employeeType;
    }

    @Override
    public String toString() {
        return "FitnessEmployees{" +
                "Name='" + Name + '\'' +
                ", CPR='" + CPR + '\'' +
                ", Hours=" + Hours +
                ", Salary=" + Salary +
                ", Vacation=" + Vacation +
                ", EmployeeType='" + EmployeeType + '\'' +
                '}';
    }
}

Upvotes: 1

Related Questions