In: Computer Science
EMPLOYEE (Inheritance)
N: New employee
P: Compute paychecks
R: Raise wages
L: List all employees
Q: Quit
Enter command: n
Enter name of new employee: Plumber, Phil
Hourly (h) or salaried (s): h
Enter hourly wage: 40.00 (Note: Do Not VALIDATE)
N: New employee
P: Compute paychecks
R: Raise wages
L: List all employees
Q: Quit
Enter command: n
Enter name of new employee: Coder, Carol
Hourly (h) or salaried (s): s
Enter annual salary: 80000.00 (Note: Do not VALIDATE.)
N: New employee
P: Compute paychecks
R: Raise wages
L: List all employees
Q: Quit
Enter command: p
Enter number of hours worked per week by plumber, Phil: 50
Pay: $2,200 (NOTE: This is calculated by the program
based on regular and overtime pay )
Enter number of hours worked per week by Coder, Carol: 50
Pay: $1,538.46 (NOTE: This is calculated by the program.
Divide salary by 52(weeks))
N: New employee
P: Compute paychecks
R: Raise wages
L: List all employees
Q: Quit
Enter command: r
Enter percentage increase: 4.5
Name New Wages
--------------- -----------------
Plumber, Phil $41.80/hour
Coder, Carol $83,600.00/year
(NOTE: For hourly, display hourly wage; for salary, display annual
salary.)
N: New employee
P: Compute paychecks
R: Raise wages
L: List all employees
Q: Quit
Enter command: L
Name hourly wages
--------------- -----------------
Plumber, Phil $41.80/hour
Coder, Carol $32.15/hour NOTE: Divide salary by 52
and then further divide by the number of hours worked per week. If no hours are provided
assume 40 hours per week.
Enter command : q
The program will repeatedly prompt the user to enter a command, which it then executes. The program will not terminate until the user enters the command q. Note that the list of commands is redisplayed after each command has been executed.
Write three classes that store information about an employee
Employee (abstract). Instances of this class will store an employee name and the employee’s hourly wage. Methods will include getters and setters for the name and hourly wage; a method that increases the hourly wage by a given percentage and an abstract method named computePay that computes the weekly pay for the employee when given the number of hours worked.
Hourly Employee extends Employee. The constructor will take a name and hourly wage as its parameters. Methods will include computePay and toString. To determine the employee’s pay, computePay multiplies the first 40 (or fewer) hours by the employee’s hourly wage. Hours worked beyond 40 are paid at time and a half(1.5 times the hourly wage). toString returns a string containing the employee’s name and hourly wage.
SalariedEmployee extends Employee. The constructor will take a name and annual salary as its parameters. Methods will include a getter and a setter for the annual salary, along with computePay and toString. (Note that the salary will need to be converted to an hourly wage, because that’s what the Employee class requires. To do this conversion, assume that a salaried employee works 40 hours a week for 52 weeks). computePay always returns 1/52 of the annual salary, regardless of the number of hours worked. toString returns a string containing the employee’s name and annual salary.
Use an array to store the employee records. Each element of the array will store a reference to an Hourly Employee object or a SalariedEmployee object. The array used to store employee objects must contain only one element initially. When the array becomes full, it must be doubled in size.
Here are a few other requirements for the program:
abstract class Employee {
String empName;
double empWage;
static int empCount;
{ }
void increaseEmpWage(double increasePerc) { }
abstract double computePay();
}
class HourlyEmployee extends Employee {
double hours;
HourlyEmployee(String empName, double empWage) { }
double computePay() { //compute both regular time and overtime
based on hours }
String toString() { //return empname and wage }
}
class SalariedEmployee extends Employee {
SalariedEmployee(String empName, double annualSalary) { //set name
and wage divide by 52, divide by 40 }
double computePay() { Multiply wage by 40 }
String toString() { //return empname and annual salary }
}
class EmployeeDriver {
//declare array
public static void main(String[] args) {
//display menu in a do/while loop (call menu and selectOptions methods)
}
public static String employeeMenu() {//display menu and return
user’s selection}
public static selectOptions (String user) {
switch (user){
case "N": newEmployee();
case "P": computePaycheck();
case "R": raiseWages();
case "L": listEmployees();
}
public static void newEmployee() {
//grab input from user such as name, whether the employee is hourly
or salaried,
//hourly wage or salary
//create employee object based on the input
//expand array as needed and assign new object to the proper index
of the array
}
public static void computeWeeklyPaycheck() {
//display weekly pay for all employees using a loop.
//For hourly employees first grab hours, set hours to instance variable
//then call computePay which will call the
//appropriate overridden method for either hourly or salaried employee
}
public static void raiseWages() {
//grab percentage from user and raise empWage for all employees
using loop
}
public static void listEmployees() {
//display information for all employees using loop and toString
method
}
}
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// Employee.java
public abstract class Employee {
String empName;
double empWage;
public Employee(String empName, double empWage)
{
this.empName = empName;
this.empWage = empWage;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName)
{
this.empName = empName;
}
public double getEmpWage() {
return empWage;
}
public void setEmpWage(double empWage)
{
this.empWage = empWage;
}
public void increaseEmpWage(double
increasePerc)
{
this.empWage+=empWage*(increasePerc/100);
}
abstract double computePay(int hoursWorked);
}
_______________________
// HourlyEmployee.java
public class HourlyEmployee extends Employee {
public HourlyEmployee(String empName,
double empWage) {
super(empName, empWage);
}
public String toString() {
return getEmpName() + "\t$" +
getEmpWage()+"/ per hour";
}
double computePay(int hoursWorked)
{
double wage = 0;
if (hoursWorked <= 40) {
wage =
hoursWorked * getEmpWage();
} else if (hoursWorked > 40)
{
wage =
40*getEmpWage()+ (hoursWorked-40) * getEmpWage() * 1.5;
}
return wage;
}
}
___________________________
// SalariedEmployee.java
public class SalariedEmployee extends Employee
{
private double annualSalary;
public SalariedEmployee(String empName,
double annualSalary) {
super(empName, annualSalary / (40 *
52));
this.annualSalary =
annualSalary;
}
public double getAnnualSalary() {
return annualSalary;
}
public void setAnnualSalary(double
annualSalary) {
this.annualSalary =
annualSalary;
}
double computePay(int hoursWorked) {
return (annualSalary
/ 52);
}
public String toString() {
return getEmpName() + "\t$" +
getEmpWage()+"/ per Hour";
}
}
_____________________________
// Test.java
import java.util.Scanner;
public class Test {
/*
* Creating an Scanner class object which is used to
get the inputs
* entered by the user
*/
static Scanner sc = new Scanner(System.in);
static Employee emps[]=null;
static int empCount=0;
public static void main(String[] args) {
emps=new Employee[1];
String choice="";
choice=employeeMenu();
do
{
selectOptions(choice);
choice=employeeMenu();
}while(!choice.equalsIgnoreCase("Q"));
}
public static String employeeMenu()
{
String choice="";
System.out.println("\nN: New
employee");
System.out.println("P: Compute
paychecks");
System.out.println("R: Raise
wages");
System.out.println("L: List all
employees");
System.out.println("Q:
Quit");
System.out.print("Enter command:
");
choice=sc.next();
choice=choice.toUpperCase();
return choice;
}
public static void selectOptions (String user) {
sc.nextLine();
switch (user){
case "N": newEmployee();
break;
case "P": computePaycheck();
break;
case "R": raiseWages();
break;
case "L": listEmployees();
break;
case "Q" : break;
}
}
private static void listEmployees() {
System.out.println("Name\tNew
Wages");
System.out.println("-----\t--------");
for(int i=0;i<empCount;i++)
{
System.out.println(emps[i]);
}
}
private static void raiseWages() {
System.out.print("Enter percentage
increase: ");
double raise=sc.nextDouble();
System.out.println("Name\tNew
Wages");
System.out.println("-----\t--------");
for(int i=0;i<empCount;i++)
{
emps[i].increaseEmpWage(raise);
System.out.println(emps[i]);
}
}
private static void computePaycheck() {
int hours;
for(int
i=0;i<empCount;i++)
{
System.out.print("Enter number of hours worked per week by
"+emps[i].getEmpName()+":");
hours=sc.nextInt();
System.out.println("Pay: $"+emps[i].computePay(hours));
}
}
private static void newEmployee() {
if(empCount==emps.length)
{
Employee es[]=new
Employee[2*emps.length];
for(int
i=0;i<empCount;i++)
{
es[i]=emps[i];
}
emps=es;
}
System.out.print("Enter name of new
employee:");
String name=sc.nextLine();
System.out.print("Hourly (h) or
salaried (s):");
char salOrHour=sc.next(".").charAt(0);
if(salOrHour=='h' || salOrHour=='H')
{
System.out.print("Enter hourly wage: $");
double hourlyWage=sc.nextDouble();
HourlyEmployee h=new
HourlyEmployee(name,hourlyWage);
emps[empCount]=h;
empCount++;
}
else if(salOrHour=='s' || salOrHour=='S')
{
System.out.print("Enter Annual Salary: $");
double annualSal=sc.nextDouble();
SalariedEmployee se=new
SalariedEmployee(name,annualSal);
emps[empCount]=se;
empCount++;
}
}
}
__________________________
Output:
N: New employee
P: Compute paychecks
R: Raise wages
L: List all employees
Q: Quit
Enter command: n
Enter name of new employee:Plumber, Phil
Hourly (h) or salaried (s):h
Enter hourly wage: $40.00
N: New employee
P: Compute paychecks
R: Raise wages
L: List all employees
Q: Quit
Enter command: n
Enter name of new employee:Coder, Carol
Hourly (h) or salaried (s):s
Enter Annual Salary: $80000.00
N: New employee
P: Compute paychecks
R: Raise wages
L: List all employees
Q: Quit
Enter command: p
Enter number of hours worked per week by Plumber, Phil:50
Pay: $2200.0
Enter number of hours worked per week by Coder, Carol:50
Pay: $1538.4615384615386
N: New employee
P: Compute paychecks
R: Raise wages
L: List all employees
Q: Quit
Enter command: r
Enter percentage increase: 4.5
Name New Wages
----- --------
Plumber, Phil $41.8/ per hour
Coder, Carol $40.19230769230769/ per
Hour
N: New employee
P: Compute paychecks
R: Raise wages
L: List all employees
Q: Quit
Enter command: l
Name New Wages
----- --------
Plumber, Phil $41.8/ per hour
Coder, Carol $40.19230769230769/ per
Hour
N: New employee
P: Compute paychecks
R: Raise wages
L: List all employees
Q: Quit
Enter command: q
_______________Could you plz rate me well.Thank
You