Knowee
Questions
Features
Study Tools

21. Write a Java program that creates a class hierarchy for employees of a company. The base class should be Employee, with subclasses Manager, Developer, and Programmer. Each subclass should have properties such as name, address, salary, and job title. Implement methods for calculating bonuses, generating performance reports, and managing projects

Question

  1. Write a Java program that creates a class hierarchy for employees of a company. The base class should be Employee, with subclasses Manager, Developer, and Programmer. Each subclass should have properties such as name, address, salary, and job title. Implement methods for calculating bonuses, generating performance reports, and managing projects
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple implementation of the class hierarchy in Java:

// Base class
public class Employee {
    String name;
    String address;
    double salary;
    String jobTitle;

    public Employee(String name, String address, double salary, String jobTitle) {
        this.name = name;
        this.address = address;
        this.salary = salary;
        this.jobTitle = jobTitle;
    }

    public double calculateBonus() {
        return 0.1 * salary; // 10% bonus
    }

    public void generatePerformanceReport() {
        System.out.println("Generating performance report for " + name);
    }
}

// Subclass
public class Manager extends Employee {
    public Manager(String name, String address, double salary, String jobTitle) {
        super(name, address, salary, jobTitle);
    }

    public void manageProject() {
        System.out.println(name + " is managing a project");
    }
}

// Subclass
public class Developer extends Employee {
    public Developer(String name, String address, double salary, String jobTitle) {
        super(name, address, salary, jobTitle);
    }

    public void manageProject() {
        System.out.println(name + " is developing a project");
    }
}

// Subclass
public class Programmer extends Employee {
    public Programmer(String name, String address, double salary, String jobTitle) {
        super(name, address, salary, jobTitle);
    }

    public void manageProject() {
        System.out.println(name + " is programming a project");
    }
}

In this code, Employee is the base class with properties name, address, salary, and jobTitle. It has methods for calculating bonuses and generating performance reports. Manager, Developer, and Programmer are subclasses that inherit from Employee and each has a method for managing projects.

This problem has been solved

Similar Questions

EX NO: 3 PROGRAM TO GENERATE PAYSLIP USING INHERITANCE AIM To develop a java application to generate pay slip for different category of employees using the concept of inheritance. PROCEDURE 1. Create the class employee with name, Empid, address, mailid, mobileno as members. 2. Inherit the classes programmer, asstprofessor,associateprofessor and …

Create the class Employee with name, Empid, address, mailid, mobileno as data members.Inherit the classes programmer,Asstprofessor, Associateprofessor and Professor from employee class.Add Basic Pay (BP) as the member of all the inherited classes..Calculate DA as 97% of BP, HRA as 8% of BP, PF as 10% of BP, Staff club fund as 0.1% of BP.Calculate gross salary and net salary.Generate payslip for programmer categories of employees.Calculate DA as 97% of BP, HRA as 10% of BP, PF as 12% of BP, Staff club fund as 0.1% of BP.Calculate gross salary and net salary.Generate payslip for Asstprofessor categories of employees.Calculate DA as 97% of BP, HRA as 7% of BP, PF as 13% of BP, Staff club fund as 0.1% of BP.Calculate gross salary and net salary.Generate payslip for Associateprofessor categories of employees, Create the objects for the inherited classes and invoke the necessary methods to display the Payslip.Calculate DA as 97% of BP, HRA as 4% of BP, PF as 13% of BP, Staff club fund as 0.2% of BP.Calculate gross salary and net salary.Generate payslip for Professor categories of employees,Choose the options 1.PROGRAMMER 2.ASSISTANT PROFESSOR 3.ASSOCIATE PROFESSOR 4.PROFESSORinput2Arun [email protected], Anna Nagar, Chennai-6550029876543210 20000outputArun [email protected] 12, Anna Nagar, Chennai65987654321020000.019400.02000.02400.02000.041400.037000.0

Design a class named Person and its two subclasses named Student and Employee.  Make Faculty and Staff subclasses of Employee. A person has a name,  address, phone_number, and e-mail address. A student has a status (freshman, sophomore, junior, or senior).  An employee  has an office, salary. A faculty member has office_hours and a rank. A staff member has a title. Override the toString() method in each of these classes to display their details. Write a Java application and subsequent pseudocode to implement/simulate the same.

[25 points] Write a Java class named Employee such that the class contains threeattributes empName, salary, and departmentName. You should be able to createobjects of this class by supplying values to any one, two, or all three of the attributes. Ifno value is supplied during the object creation, the attributes should be initialized withsome default values. You are expected to use 'this' keyword to achieve the result. Discussthe ways in which you can change or reset the attribute values of the objects created.Write appropriate mutator methods that store values in these fields and accessormethods that return the values in these fields. Once you have written the class, write aseparate program that creates three Employee objects to hold the following data:Employee Name Department Salary---------------------------------------------------------------------Susan Meyers Accounting 5000.00Mark Jones IT 8375.00Joy Rogers Manufacturing 6380.00---------------------------------------------------------------------The program should store this data in the three objects and then display the data for eachemployee on the screen

Q1. Create an Employee class with the relevant attributes and methods in addition of thefollowing specifications:  It contains a default constructor. It contains a parameterized constructor. It contains a copy constructor.Note: Each student should have different their own version and it is better to have morethe attributes and methods.Q2. Incorporate static attributes and static methods in the Employee class where required.note for chatgpt/bard : computer languages used for code is c#

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.