Question

In: Computer Science

Specifications Create an abstract Employee class that provides private attributes for the first name, last name,...

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 should add private attributes for years of experience and the annual salary. This class should also provide necessary set and get functions. It should add a bonus ($1,000/year of experience) to the annual salary. The income tax rate should be 30%. This class should override the get_net_income function of the Employee class. Note that the gross income is calculated as follows:
    • bonus = years of experience * 1000
    • gross income = annual salary + bonus
    • tax rate = 30%
    • income tax = gross income * tax rate
    • net income = gross income - income tax
  • Create a Representative class that inherits the Employee class. This class should add private attributes for the weekly hours of work and the pay rate. This class should also provide necessary set and get functions. The income tax rate should be 20%. This class should override the get_net_income function of the Employee class. Note that the gross income is calculated as follows:
    • gross income = weekly hours of work * 52 * pay rate
    • tax rate = 20%
    • income tax = gross income * tax rate
    • net income = gross income - income tax
  • In the main function, the program should create Manager or Representative objects from the data entered by the user and save them in a list named employees. After the user has terminated data entries, your program should display the information of all employees on the output with this format: last name, first name, email, social security number, net income.

Sample Output (Your output should be similar to the text in the following box)

Welcome to my app

EMPLOYEE DATA ENTRY

Manager or Representative? (m/r): d

Invalid selection.

Continue? (y/n): y

Manager or Representative? (m/r): m

First Name: Frank
Last Name: Wilson
Email Address: [email protected]
SSN: 111-22-3333
Years of Experience: 3
Annual Salary: 95000

Continue? (y/n): y

Manager or Representative? (m/r): r

First Name: John
Last Name: Atkins
SSN: 222-33-4444
Email Address: [email protected]
Weekly Hours of Work: 40
Pay Rate: 20

Continue? (y/n): n

EMPLOYEE INFORMATION
Wilson, Frank, [email protected], 111-22-3333, $68600.00
Atkins, John, [email protected], 222-33-4444, $33280.00

Thank you for using my app

Solutions

Expert Solution

Following is the answer:

Employee.java

public class Employee {
    private String firstName;
    private String lastName;
    private String email;
    private int ssn;

    Employee(){}

    Employee(String firstName, String lastName, String email, int ssn){
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
        this.ssn = ssn;
    }

    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 getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getSsn() {
        return ssn;
    }

    public double get_net_income(){
        return 0;
    }

    public void setSsn(int ssn) {
        this.ssn = ssn;
    }
}

Manager.java

public class Manager extends Employee {
    private double expr;
    private double annualSalary;

    Manager(String firstName, String lastName, String email, int ssn, double expr, double annualSalary){
        super(firstName, lastName, email, ssn);
        this.expr = expr;
        this.annualSalary = annualSalary;
    }

    public double getExpr() {
        return expr;
    }

    public void setExpr(double expr) {
        this.expr = expr;
    }

    public double getAnnualSalary() {
        return annualSalary;
    }

    public void setAnnualSalary(double annualSalary) {
        this.annualSalary = annualSalary;
    }

    @Override
    public double get_net_income() {
        double bonus = expr * 1000;
        double grossincome = annualSalary + bonus;
        double tax = grossincome * 0.30;
        return grossincome - tax;
    }

    @Override
    public String toString() {
        return super.getFirstName() + ", "  + super.getLastName() + ", " + super.getEmail() + ", " + super.getSsn() + ", " + this.get_net_income();
    }
}

Representative.java

public class Representative extends Employee {
    private int hours;
    private double payRate;

    Representative(String firstName, String lastName, String email, int ssn, int hours, double payRate){
        super(firstName, lastName, email, ssn);
        this.hours = hours;
        this.payRate = payRate;
    }

    public int getHours() {
        return hours;
    }

    public void setHours(int hours) {
        this.hours = hours;
    }

    public double getPayRate() {
        return payRate;
    }

    public void setPayRate(double payRate) {
        this.payRate = payRate;
    }

    @Override
    public double get_net_income() {
        double gross = hours * 52 * payRate;
        double tax = gross * 0.20;
        return gross-tax;
    }

    @Override
    public String toString() {
        return super.getFirstName() + ", "  + super.getLastName() + ", " + super.getEmail() + ", " + super.getSsn() + ", " + this.get_net_income();
    }
}

Emp.java(main)

import java.util.ArrayList;
import java.util.Scanner;

public class Emp {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Welcome to the app");
        char choice = 0;
        ArrayList<Employee> arr = new ArrayList<Employee>();
        do{
            System.out.println("EMPLOYEE DATA ENTRY");
            char ch;
            System.out.println("Manager or Representative? (m/r): ");
            ch = sc.next().charAt(0);
            if(ch == 'm' || ch == 'r'){
            switch (ch){
                case 'm':
                    System.out.println("First name: ");
                    String firstname = sc.next();
                    System.out.println("Last name: ");
                    String lastname = sc.next();
                    System.out.println("Email:");
                    String email = sc.next();
                    System.out.println("SSN");
                    int ssn = sc.nextInt();
                    System.out.println("Years of Experience: ");
                    int year = sc.nextInt();
                    System.out.println("Annual Salary: ");
                    double salary = sc.nextDouble();
                    Manager m = new Manager(firstname,lastname,email,ssn,year,salary);
                    arr.add(m);
                    break;

                case 'r':
                    System.out.println("First name: ");
                    String firstname1 = sc.next();
                    System.out.println("Last name: ");
                    String lastname1 = sc.next();
                    System.out.println("Email:");
                    String email1 = sc.next();
                    System.out.println("SSN");
                    int ssn1 = sc.nextInt();
                    System.out.println("Weekly Hours of Work: ");
                    int hours = sc.nextInt();
                    System.out.println("Pay Rate: ");
                    double payrate = sc.nextDouble();
                    Representative r = new Representative(firstname1,lastname1,email1,ssn1,hours,payrate);
                    arr.add(r);
                    break;
            }
            }else{
                System.out.println("Invalid selection.");
            }
            System.out.println("Continue? (y/n):");
            choice = sc.next().charAt(0);
        }while (choice == 'y');
        System.out.println("EMPLOYEE INFORMATION");

        for(int i = 0 ; i < arr.size() ; i++){
            System.out.println(arr.get(i).toString());
        }
    }
}

Output:


Related Solutions

Create a class Employee. Your Employee class should include the following attributes: First name (string) Last...
Create a class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyEmployee that inherits from the Employee class.   HourEmployee must use the inherited parent class variables and add in HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games,...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If there are...
Please Code Using Java Create a class called SoccerPlayer Create 4 private attributes: First Name, Last...
Please Code Using Java Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If...
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double)...
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double) Create getter/setter methods for all attributes Create a constructor that takes in all attributes and sets them Remove the default constructor Override the toString() method and return a String that represents the building object that is formatted nicely and contains all information (attributes) Create a FoodProduct Class that extends Product Add the following private attributes: expDate (java.util.Date) for expiration date refrigerationTemp (int) if 70...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All the attributes must be String) Create a constructor that accepts first name and last name to create a student object. Create appropriate getters and setters Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed. In the main program, create student objects, with the following first and last names. Chris...
C# (Thank you in advance) Create an Employee class with five fields: first name, last name,...
C# (Thank you in advance) Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields. Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary. Create a Worker classes that is derived from Employee and SalaryCalculate...
Write a class named Person with data attributes for a person’s first name, last name, and...
Write a class named Person with data attributes for a person’s first name, last name, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number and a Boolean data attribute indicating whether the customer wishes to be on a calling list. Demonstrate an instance of the Customer class in a simple program. Using python
In Java, Here is a basic Name class. class Name { private String first; private String...
In Java, Here is a basic Name class. class Name { private String first; private String last; public Name(String first, String last) { this.first = first; this.last = last; } public boolean equals(Name other) { return this.first.equals(other.first) && this.last.equals(other.last); } } Assume we have a program (in another file) that uses this class. As part of the program, we need to write a method with the following header: public static boolean exists(Name[] names, int numNames, Name name) The goal of...
Part I: The Employee Class You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class.
  Part I:   The Employee Class You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class. * Update the function display() to be a virtual function     * Add function, double weeklyEarning() to be a pure virtual function. This will make Employee an abstract class, so your main will not be able to create any Employee objects. Part II: The Derived Classes Add an weeklyEarning() function to each...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT