user16718623
user16718623

Reputation: 1

I cannot create the super class dont know why

A construction company wants to keep a record of the employees working in it. There are permanent employees as well as contract employees. Contract employees work on an hourly basis whereas permanent employees are paid monthly salary. An application needs to be developed for the company for storing the employee details.

Class diagram

Employee

Employee(int employeeId, String employeeName)

Initialize the employeeId and employeeName instance variables appropriately with the values passed to the constructor. Implement the getter and setter methods appropriately.

PermanentEmployee

PermanentEmployee(int empId, String name, double basicPay, double hra, float experience)

Initialize the employeeId, employeeName, basicPay, hra and experience instance variables appropriately with the values passed to the constructor. IP op

package wer;

public class Employee {
private int employeeId;
private String employeeName;
private double salary;

    public Employee() {
    
    }
    public Employee(int employeeId, String employeeName) {
        this.employeeId = employeeId;
        this.employeeName = employeeName; 
        
    }
    public int getEmployeeId() {
        return employeeId;
    }public void setEmployeeeId(int employeeId) {
        this.employeeId = employeeId;
        
    }public String getEmployeeName() {
        return employeeName;
    }public void setEmployeeName(String employeeName) {
        this.employeeName = employeeName;
    }public double getSalary() {
        return salary;
    }public void setSalary(double salary) {
        this.salary = salary;
    }
    public String toString(){
        return "Employee\nemployeeId: "+this.getEmployeeId()+"\nemployeeName: "+this.getEmployeeName()+"\nsalary: "+this.getSalary();
    }
    
}



package wer;

public class PermanentEmployee extends Employee {
    private int empId;
    private String name;
    //private double salary;
    private double basicPay;
    private double hra;
    private float experience;

    PermanentEmployee(int empId, String name, double basicPay, double hra, float experience){
        
        super(employeeId,employeeName);
        this.empId = empId;
        this.name = name;
        this.basicPay = basicPay;
        this.hra = hra;
        this.experience = experience;
    }
}

Upvotes: 0

Views: 153

Answers (1)

azro
azro

Reputation: 54168

The PermanentEmployee should not have empId, name attributs, there are in its parent class Employee

class PermanentEmployee extends Employee {
    private double basicPay;
    private double hra;
    private float experience;

    PermanentEmployee(int empId, String name, double basicPay, double hra, float experience) {
        super(empId, name);
        this.basicPay = basicPay;
        this.hra = hra;
        this.experience = experience;
    }
}

class ContractEmployee extends Employee {
    private double wage;
    private float hoursWorked;

    ContractEmployee(int empId, String name, double wage, float hoursWorked) {
        super(empId, name);
        this.wage = wage;
        this.hoursWorked = hoursWorked;
    }
}

Upvotes: 1

Related Questions