Answer to Question #317377 in Java | JSP | JSF for Chen

Question #317377

1. Create four (4) Java classes. Name them RunEmployee, Employee, FullTimeEmployee, 

PartTimeEmployee. The RunEmployee class shall contain the main method and will be used to 

execute the program.

2. Write a simple payroll program that will display employee’s information. Refer to the UML Class 

Diagram for the names of the variable and method. This should be the sequence of the program 

upon execution:

a. Ask the user to input the name of the employee.

b. Prompt the user to select between full time and part time by pressing either F (full time) or P

(part time). 

c. If F is pressed, ask the user to type his monthly salary. Then, display his name and monthly 

salary.

If P is pressed, ask the user to type his rate (pay) per hour and the number of hours he worked 

for the entire month separated by a space. Then, display his name and wage.


1
Expert's answer
2022-03-24T07:49:35-0400
abstract class Employee {

    private String employeeName;

    public Employee(String name) {
        setName(name);
    }

    public void setName(String name) {
        this.employeeName = name;
    }

    public String getName() {
        return employeeName;
    }
}

final class FullTimeEmployee extends Employee {
    private double monthlySalary;

    public FullTimeEmployee(String name) {
        super(name);
    }

    public void setMonthlySalary(double salary) {
        this.monthlySalary = salary;
    }

    public double getMonthlySalary() {
        return this.monthlySalary;
    }

    public String toString() {
        return "\nEmployee Name: " + getName()  + "\nMonthly Salary: " + monthlySalary;
    }
}

final class PartTimeEmployee extends Employee {
    private double ratePerHour;
    private int hoursWorked;
    private double wage;

    public PartTimeEmployee(String name) {
        super(name);
    }

    public void setWage(double rate, int hours) {
        ratePerHour = rate;
        hoursWorked = hours;
        wage = ratePerHour * hoursWorked;
    }

    public double getWage() {
        return wage;
    }

    public String toString() {
        return "\nEmployee Name: " + getName()  + "\nWage: " + wage;
    }
}

//Run Employee
import java.util.Scanner;

public class RunEmployee {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        System.out.print("Enter Employee Name: ");
        String name = in.nextLine();

        System.out.println("Employee Types: F - Full Time, P - Part Time");
        System.out.print("Enter Employee Type:");
        String type = in.nextLine();
        if (type.compareToIgnoreCase("F") == 0) {
            FullTimeEmployee employee = new FullTimeEmployee(name);

            System.out.print("\nEnter Monthly Salary: ");
            employee.setMonthlySalary(in.nextDouble());

            System.out.println(employee);
        } else if(type.compareToIgnoreCase("P") == 0) {
            PartTimeEmployee employee = new PartTimeEmployee(name);

            System.out.print("\nEnter Rate Per Hour: ");
            double rate = in.nextDouble();

            System.out.print("\nEnter Number of Hours Worked: ");
            employee.setWage(rate, in.nextInt());

            System.out.println(employee);
        } else {
            System.out.println("Error: Invalid Employee Type!");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS