Question

Design and implement an Employee Payment System using single inheritance. This system will support three types of employees t
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//----- Employee.java -------

public class Employee {

private String firstName;

private String lastName;

private String address;

private String telephoneNumner;

private String socialSecurityNumber;

private double monthlyPaymentRate;

protected static final int TAX_RATE = 20;

public String getFirstName() {

return firstName;

}

public void setFirstName(String firstName) {

this.firstName = firstName;

}

public String getLastName() {

return lastName;

}

public void setLastName(String lastName) {

this.lastName = lastName;

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

public String getTelephoneNumner() {

return telephoneNumner;

}

public void setTelephoneNumner(String telephoneNumner) {

this.telephoneNumner = telephoneNumner;

}

public String getSocialSecurityNumber() {

return socialSecurityNumber;

}

public void setSocialSecurityNumber(String socialSecurityNumber) {

this.socialSecurityNumber = socialSecurityNumber;

}

public double getMonthlyPaymentRate() {

return this.monthlyPaymentRate;

}

public void setMonthlyPaymentRate(double monthlyPaymentRate) {

this.monthlyPaymentRate = monthlyPaymentRate;

}

public double calculateAnnualSalary() {

double annualSalary = getMonthlyPaymentRate() * 12;

return annualSalary;

}

public double calculateAtualPayment() {

double actualPayment = calculateAnnualSalary();

System.out.println("\t Annual Salary :"+actualPayment);

double totalTax = actualPayment * TAX_RATE / 100;

System.out.println("\t Total Tax :"+totalTax);

actualPayment = actualPayment - totalTax;

System.out.println("\t-------------------------------");

System.out.println("\t Total Payment :"+actualPayment);

return actualPayment;

}

}

// ----- Technician.java ---------

public class Technician extends Employee{

private int overtimeHours;

private double overtimeRate;

public int getOvertimeHours() {

return overtimeHours;

}

public void setOvertimeHours(int overtimeHours) {

this.overtimeHours = overtimeHours;

}

public double getOvertimeRate() {

return overtimeRate;

}

public void setOvertimeRate(double overtimeRate) {

this.overtimeRate = overtimeRate;

}

@Override

public double calculateAtualPayment() {

double actualPayment = calculateAnnualSalary();

System.out.println("\t Annual Salary :"+actualPayment);

double overtimePayment = getOvertimeHours() * getOvertimeRate();

System.out.println("\t Over-Time Payment :"+overtimePayment);

actualPayment = calculateAnnualSalary() + overtimePayment;

double totalTax = actualPayment * TAX_RATE / 100;

System.out.println("\t Total Tax :"+totalTax);

actualPayment = actualPayment - totalTax;

System.out.println("\t-------------------------------");

System.out.println("\t Total Payment :"+actualPayment);

return actualPayment;

}

}

// -------- Engineer.java ----------

public class Engineer extends Employee {

}

// ------ Manager.java ----------

public class Manager extends Employee {

private static final int BONUS_RATE = 3;

private boolean isExcellentPerformer;

public boolean isExcellentPerformer() {

return isExcellentPerformer;

}

public void setExcellentPerformer(boolean isExcellentPerformer) {

this.isExcellentPerformer = isExcellentPerformer;

}

@Override

public double calculateAtualPayment() {

double actualPayment = calculateAnnualSalary();

System.out.println("\t Annual Salary :"+actualPayment);

double bonus = 0.0;

if(isExcellentPerformer()) {

bonus = actualPayment * BONUS_RATE / 100;

actualPayment = actualPayment + bonus;

}

System.out.println("\t Total Bonus :"+bonus);

double totalTax = actualPayment * TAX_RATE / 100;

System.out.println("\t Total Tax :"+totalTax);

actualPayment = actualPayment - totalTax;

System.out.println("\t-------------------------------");

System.out.println("\t Total Payment :"+actualPayment);

return actualPayment;

}

// ---------- PayrollProcessor.java --------------

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class PayrollProcessor {

private static List<Employee> employees = new ArrayList<>();

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int opt = 0;

do {

System.out.println("Choose operation : ");

System.out.println("1. Enter Technician Details.");

System.out.println("2. Enter Engineer Details.");

System.out.println("3. Enter Manager Details.");

System.out.println("4. Display Annual Payment Information.");

System.out.println("5. Exit.");

opt = Integer.parseInt(scanner.nextLine());

switch(opt) {

case 1 :

employees.add(getTechnicianDetails(scanner));

break;

case 2 :

employees.add(getEngineerDetails(scanner));

break;

case 3 :

employees.add(getManagerDetails(scanner));

break;

case 4 :

displayAnnualPaymentInformation();

break;

case 5 :

System.out.println("Exiting System....!");

return;

default :

System.out.println("Incorrect input ! Choose proper option.");

break;

}

} while (opt != 5);

scanner.close();

}

private static Technician getTechnicianDetails(Scanner scanner) {

Technician technician = new Technician();

System.out.print("First Name:");

technician.setFirstName(scanner.nextLine());

System.out.print("Last Name:");

technician.setLastName(scanner.nextLine());

System.out.print("Address:");

technician.setAddress(scanner.nextLine());

System.out.print("Telephone Number:");

technician.setTelephoneNumner(scanner.nextLine());

System.out.print("Social Security Number:");

technician.setSocialSecurityNumber(scanner.nextLine());

System.out.print("Monthly Payment:");

technician.setMonthlyPaymentRate(Double.parseDouble(scanner.nextLine()));

System.out.print("Over Time Hours:");

technician.setOvertimeHours(Integer.parseInt(scanner.nextLine()));

System.out.print("Over Time Rate:");

technician.setOvertimeRate(Double.parseDouble(scanner.nextLine()));

System.out.print("Technician Information Added Successfully..!\n\n");

return technician;

}

private static Engineer getEngineerDetails(Scanner scanner) {

Engineer engineer = new Engineer();

System.out.print("First Name:");

engineer.setFirstName(scanner.nextLine());

System.out.print("Last Name:");

engineer.setLastName(scanner.nextLine());

System.out.print("Address:");

engineer.setAddress(scanner.nextLine());

System.out.print("Telephone Number:");

engineer.setTelephoneNumner(scanner.nextLine());

System.out.print("Social Security Number:");

engineer.setSocialSecurityNumber(scanner.nextLine());

System.out.print("Monthly Payment:");

engineer.setMonthlyPaymentRate(Double.parseDouble(scanner.nextLine()));

System.out.print("Engineer Information Added Successfully..!\n\n");

return engineer;

}

private static Manager getManagerDetails(Scanner scanner) {

Manager manager = new Manager();

System.out.print("First Name:");

manager.setFirstName(scanner.nextLine());

System.out.print("Last Name:");

manager.setLastName(scanner.nextLine());

System.out.print("Address:");

manager.setAddress(scanner.nextLine());

System.out.print("Telephone Number:");

manager.setTelephoneNumner(scanner.nextLine());

System.out.print("Social Security Number:");

manager.setSocialSecurityNumber(scanner.nextLine());

System.out.print("Monthly Payment:");

manager.setMonthlyPaymentRate(Double.parseDouble(scanner.nextLine()));

System.out.println("Is he a excellent performer(Y/N):");

manager.setExcellentPerformer(scanner.nextLine().equalsIgnoreCase("Y"));

System.out.print("Manager Information Added Successfully..!\n\n");

return manager;

}

private static void displayAnnualPaymentInformation() {

for(Employee emp : employees) {

displayEmployeeInfo(emp);

}

}

private static void displayEmployeeInfo(Employee emp) {

System.out.println("First Name : "+emp.getFirstName());

System.out.println("Last Name : "+emp.getLastName());

System.out.println("Address : "+emp.getAddress());

System.out.println("Telephone Number : "+emp.getTelephoneNumner());

System.out.println("Social Security Number : "+emp.getSocialSecurityNumber());

System.out.println("Payment Information : "+ emp.calculateAtualPayment());

}

}

// Sample output

Choose operation: 1. Enter Technician Details. 2. Enter Engineer Details 3. Enter Manager Details. 4. Display Annual Payment

Choose operation: 1. Enter Technician Details. 2. Enter Engineer Details. 3. Enter Manager Details. 4. Display Annual Payment

Choose operation 1. Enter Technician Details. 2. Enter Engineer Details. 3. Enter Manager Details. 4. Display Annual Payment

Choose operation: 1. Enter Technician Details. 2. Enter Engineer Details. 3. Enter Manager Details. 4. Display Annual Payment

Add a comment
Know the answer?
Add Answer to:
Design and implement an Employee Payment System using single inheritance. This system will support three types...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses...

    Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses the following menu and can perform all menu items: Enter a payroll record for one person Display all paycheck stubs Display total gross payroll from all pay records. Quit program The program will reuse the DATE struct from the previous assignment.  You should also copy in the functions relating to a DATE. The program will create a PAYRECORD struct with the following fields: typedef struct...

  • c++ only Design a class representing an Employee. The employee would have at least these private...

    c++ only Design a class representing an Employee. The employee would have at least these private fields (Variables): name: string (char array) ID: string (char array) salary: float Type: string (char array) All the variables except for the salary should have their respective setters and getters, and the class should have two constructors, one is the default constructor and the other constructor initializes the name,ID and type of employee with valid user input. The class should have the following additional...

  • Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person...

    Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person and its two subclasses, Student and Employee. Make Faculty and Staff subclasses of Employee. A Person object has a name, address, phone number, and email address (all Strings). A Student Object has a class status (freshman, sophomore, junior, or senior). Define the status as a final String variable. An Employee Object has an office number, salary (both ints ), and a date hired. Use...

  • ASAP Please. Python Program Description Create an object-oriented program that allows you to enter data for...

    ASAP Please. Python Program Description Create an object-oriented program that allows you to enter data for employees. Specifications Create an abstract Employee class that provides private attributes for the first name, last name, email address, and social security number. This class should provide functions that set and return the employee’s first name, last name, email address, and social security number. This class has a function: get_net_income which returns 0. Create a Manager class that inherits the Employee class. This class...

  • Serendipity Engineering, Inc. Software Development Project Program Specifications: Serendipity Engineering, Inc. is a small engineering company...

    Serendipity Engineering, Inc. Software Development Project Program Specifications: Serendipity Engineering, Inc. is a small engineering company located in a commercial park. The project manager wants you to develop a customer software package that will allow the company enter the customer information in the computer to keep a customer database. The software will perform the following tasks using menus: Enter Customer Information Display Customer Information Search Customer Information Organize (Sort) Customer Information Add, Delete, Modify, and Look Up Customer Records Save...

  • JAVA ONLY. For this assignment you will create an employee application, containing contact information, salary, and...

    JAVA ONLY. For this assignment you will create an employee application, containing contact information, salary, and position. You will also define the type of company. Is it an engineering firm, a supermarket, or a call center? Once the application has been completed, I should be able to perform a query for any piece of information associated with each employee.   For instance, if I search for employees who make over $50,000, all of the employees whose salaries are greater than $50,000 should...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

  • I NEED ALL QUESTIONS OR ELSE THUMBS DOWN! C++ Implement a structure Employee. An employee has...

    I NEED ALL QUESTIONS OR ELSE THUMBS DOWN! C++ Implement a structure Employee. An employee has a name (a char *) and a salary (a double). Write a default constructor, a constructor with two parameters (name and salary), and methods char* getName() double getSalary() to return the name and salary. Write a small global function TestEmployee() to test your structure. Creating a new employee. Please type the name: Larry Bird Please specify the salary: 200000 New employee has been created....

  • Visual C# C# Visual Studio 2017 You are to create a class object called “Employee” which included eight private variable...

    Visual C# C# Visual Studio 2017 You are to create a class object called “Employee” which included eight private variables - firstN - lastN - idNum -wage: holds how much the person makes per hour -weekHrsWkd: holds how many total hours the person worked each week. - regHrsAmt: initialize to a fixed amount of 40 using constructor. - regPay - otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: -...

  • 0.Use Factory Design Method 1. Implement an interface called EmployeeInfo with the following constant variables: FACULTY_MONTHLY_SALARY...

    0.Use Factory Design Method 1. Implement an interface called EmployeeInfo with the following constant variables: FACULTY_MONTHLY_SALARY = 6000.00 STAFF_MONTHLY_HOURS_WORKED = 160 2. Implement an abstract class Employee with the following requirements: Attributes last name (String) first name (String) ID number (String) Sex - M or F Birth date - Use the Calendar Java class to create a date object Default argument constructor and argument constructors. Public methods toString - returning a string with the following format: ID Employee number :_________...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT