Knowee
Questions
Features
Study Tools

Create a Java  base class called Employee. Use this class to store two double-type values that could be used to compute the salary of employees. Also,the base class should have a static variable ‘totalemp’  to keep track of the total number of employees created. Derive two specific classes called part_time and full_time from the base employee. Add a member function called as get_basic() to get the basic pay and another member called display_salary() to compute and display the salary of the employees. Using these three classes, design a program that will accept the basic pay of part_time and full_time employees interactively. Remember the two values given as input will be treated as the basic pay of the employees and the following information is used for calculating the salaries of both the part-time as well as full-time employees. Print invalid if the basic_salary of part-time employee and basic_salary of full-time employee are not met the ”Boundary Condition”Part time                                         Full timeHRA = 20% of basic pay                    HRA = 30% of basic payDA = 72% of basic pay                      DA = 80% of basic paySalary = Basic + HRA + DA              Salary = Basic + HRA + DABoundary Condition:0 < basic_salary of part-time employee <= 10000000 < basic_salary of full-time employee <= 1000000Input Format:First line to enter the basic_salary of part-time employee and basic_salary of full-time employeeOutput Format:Total salary of part-time employee and total salary of full-time employee.Total number of employees processed Sample Testcase Input-1:50007000000Sample Testcase Output-1:8900.0invalid1 Sample Testcase Input-2:30000600000Sample Testcase Output-2:42720.0110400.02 Sample Testcase Input-3:0900000Sample Testcase Output-3:invalid216000.01

Question

Create a Java  base class called Employee. Use this class to store two double-type values that could be used to compute the salary of employees. Also,the base class should have a static variable ‘totalemp’  to keep track of the total number of employees created. Derive two specific classes called part_time and full_time from the base employee. Add a member function called as get_basic() to get the basic pay and another member called display_salary() to compute and display the salary of the employees. Using these three classes, design a program that will accept the basic pay of part_time and full_time employees interactively. Remember the two values given as input will be treated as the basic pay of the employees and the following information is used for calculating the salaries of both the part-time as well as full-time employees. Print invalid if the basic_salary of part-time employee and basic_salary of full-time employee are not met the ”Boundary Condition”Part time                                         Full timeHRA = 20% of basic pay                    HRA = 30% of basic payDA = 72% of basic pay                      DA = 80% of basic paySalary = Basic + HRA + DA              Salary = Basic + HRA + DABoundary Condition:0 < basic_salary of part-time employee <= 10000000 < basic_salary of full-time employee <= 1000000Input Format:First line to enter the basic_salary of part-time employee and basic_salary of full-time employeeOutput Format:Total salary of part-time employee and total salary of full-time employee.Total number of employees processed Sample Testcase Input-1:50007000000Sample Testcase Output-1:8900.0invalid1 Sample Testcase Input-2:30000600000Sample Testcase Output-2:42720.0110400.02 Sample Testcase Input-3:0900000Sample Testcase Output-3:invalid216000.01

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is the Java code that meets your requirements:

import java.util.Scanner;

class Employee {
    static int totalemp = 0;
    double basic_pay;

    Employee(double basic_pay) {
        this.basic_pay = basic_pay;
        totalemp++;
    }

    double get_basic() {
        return basic_pay;
    }
}

class part_time extends Employee {
    part_time(double basic_pay) {
        super(basic_pay);
    }

    void display_salary() {
        if (basic_pay > 0 && basic_pay <= 100000) {
            double hra = basic_pay * 0.2;
            double da = basic_pay * 0.72;
            double salary = basic_pay + hra + da;
            System.out.println(salary);
        } else {
            System.out.println("invalid");
        }
    }
}

class full_time extends Employee {
    full_time(double basic_pay) {
        super(basic_pay);
    }

    void display_salary() {
        if (basic_pay > 0 && basic_pay <= 1000000) {
            double hra = basic_pay * 0.3;
            double da = basic_pay * 0.8;
            double salary = basic_pay + hra + da;
            System.out.println(salary);
        } else {
            System.out.println("invalid");
        }
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double part_time_basic_pay = sc.nextDouble();
        double full_time_basic_pay = sc.nextDouble();

        part_time pt = new part_time(part_time_basic_pay);
        pt.display_salary();

        full_time ft = new full_time(full_time_basic_pay);
        ft.display_salary();

        System.out.println(Employee.totalemp);
    }
}

This program creates a base class Employee with a static variable totalemp to keep track of the total number of employees created. It also has two derived classes part_time and full_time each with a method display_salary() to calculate and display the salary of the employees. The main method accepts the basic pay of part-time and full-time employees interactively and displays the total salary of each employee and the total number of employees processed.

This problem has been solved

Similar Questions

An employee will have a name, pay_rate, and list of hours_worked.Employee class must have following methods:Constructor – takes name and pay_rate. It will also creat an empty list of hours_worked.add_hours – takes hours as a parameter and add it to the hours_worked list.salary – calculates the salary for the employe (pay_rate x total hours worked).Write a main function that will:Ask user for employee name and pay rate.Create the employee object.Ask user for the number of days the employee worked.For each day it will ask the user for number of hours that employee worked and use the add_hours function to add this to the list of hours_worked in employee class.It will display the employee data as follows (use f string to format the output):Employee Name: Joe DoePay Rate: $ 25.75 per hourTotal number of hours worked: 39.45Total Salary: $ 1015.84

Create a class employee with protected members:Name,age,degree,genderCreate a member function to read the details.  Create a derived class department by inheriting the employee class privately.Declare the protected members: department_name, designation.Create a member function to read the details of the department.Create a member function to display the details of employee class and department class.Create a derived class salary by inheriting the employee class privately with protected members: basic payCreate default constructor to read basic pay.Define a member function to calculate the gross pay. Gross_pay=basic_pay+DA+HRADA=30% of basic payHRA =12% of basic payCreate a member function to display the details of employee class and the grosspay.

Define a class “employee” having employee id, name and salary use accept and to-string method to display and create n employee’s data and find the total salary of all employees and find the name of the employee who is having maximum salary.

Ask user for employee name and pay rate.Create the employee object.Ask user for the number of days the employee worked.For each day it will ask the user for number of hours that employee worked and use the add_hours function to add this to the list of hours_worked in employee class.It will display the employee data as follows (use f string to format the output):Employee Name: Joe DoePay Rate: $ 25.75 per hourTotal number of hours worked: 39.45Total Salary: $ 1015.84

You are tasked with developing a software system for managing different types of employees in a company. The company has three types of employees: full-time employees, part-time employees, and consultants. Each type of employee has different attributes and calculation methods for calculating their monthly salary.Full-time employees receive a fixed monthly salary.Part-time employees are paid based on the number of hours they work and rate per hour.Consultants are paid based on the number of hours they work and an hourly rate.Design a C++ program that utilizes runtime polymorphism to model this scenario. Create a base class Employee with virtual functions calculateSalary() and displayDetails(). Derive three classes FullTimeEmployee, PartTimeEmployee, and Consultant from Employee, each implementing its own version of calculateSalary() and displayDetails() based on the rules described above.Then, demonstrate the use of runtime polymorphism by creating an array of Employee pointers containing instances of full-time employees, part-time employees, and consultants. Populate the array with objects of each type and iterate over it, calling the calculateSalary() and displayDetails() functions for each employee. Input Format:Enter name of full-time employeeEnter monthly salaryEnter name of part-time employeeEnter hourly rateEnter hours workedEnter name of consultantEnter hourly rateEnter hours worked

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.