Question

In: Computer Science

EMPLOYEE (Inheritance) Write a program that maintains wage information for the employees of a company. The...

EMPLOYEE (Inheritance)

  1. Write a program that maintains wage information for the employees of a company. The following example shows what the user will see during a session with the program:

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:

  • Dollar amounts must be displayed correctly, with two digits after the decimal point. For example, make sure that your program displays $100.00 and not $100.0.
  • Use helper methods to convert a number into dollars and cents with the comma in the appropriate place and vice versa.


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
}
}

Solutions

Expert Solution

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


Related Solutions

Write a program in C to process weekly employee timecards for all employees of an organization...
Write a program in C to process weekly employee timecards for all employees of an organization (ask the user number of employees in the start of the program). Each employee will have three data items: an identification number, the hourly wage rate, and the number of hours worked during a given week.A tax amount of 3.625% of gross salary will be deducted. The program output should show the identification number and net pay. Display the total payroll and the average...
Write a program to process weekly employee time cards for all employees of an organization. Each...
Write a program to process weekly employee time cards for all employees of an organization. Each employee will have three data items: an identification number, the hourly wage rate, and the number of hours worked during a given week. Each employee is to be paid time and a half for all hours worked over 40. A tax amount of 3.625% of gross salary will be deducted. The program output should show the employee’s number and net pay. Display the total...
WRITE A JAVA PROGRAM - define a class that maintains information about circles in 2 dimensional...
WRITE A JAVA PROGRAM - define a class that maintains information about circles in 2 dimensional plane. Be sure to include required data members and methods to initialize a circle object. provide information on the circle and reposition the circle. do not specify any other methods . in addition make sure data members are accessible in derived classes..
Write a program of doubly Circular linked list to maintain records of employees. Take employee ID,...
Write a program of doubly Circular linked list to maintain records of employees. Take employee ID, name and salary as data of each employee. Search a particular record on ID and display the previous and next records as well. Whichever ID it give, it should display all the records because of being circular. Code needed in Java.
A company maintains three offices in a certain region, each staffed by two employees. Information concerning...
A company maintains three offices in a certain region, each staffed by two employees. Information concerning yearly salaries (1000s of dollars) is as follows: Office 1 1 2 2 3 3 Employee 1 2 3 4 5 6 Salary   36.7     40.6     37.2     40.6     32.8     36.7   (a) Suppose two of these employees are randomly selected from among the six (without replacement). Determine the sampling distribution of the sample mean salary X. (Enter your answers for p(x) as fractions.) x     34.75 36.70...
A company maintains three offices in a certain region, each staffed by two employees. Information concerning...
A company maintains three offices in a certain region, each staffed by two employees. Information concerning yearly salaries (1000s of dollars) is as follows: Office 1 1 2 2 3 3 Employee 1 2 3 4 5 6 Salary   26.7     30.6     27.2     30.6     22.8     26.7   (a) Suppose two of these employees are randomly selected from among the six (without replacement). Determine the sampling distribution of the sample mean salary X. (Enter your answers for p(x) as fractions.) x     24.75 26.70...
A company maintains three offices in a certain region, each staffed by two employees. Information concerning...
A company maintains three offices in a certain region, each staffed by two employees. Information concerning yearly salaries (1000s of dollars) is as follows: Office 1 1 2 2 3 3 Employee 1 2 3 4 5 6 Salary   24.7     28.6     25.2     28.6     20.8     24.7   (a) Suppose two of these employees are randomly selected from among the six (without replacement). Determine the sampling distribution of the sample mean salary X. (Enter your answers for p(x) as fractions.) x     22.75 24.70...
Q.Consider an organization that maintains a table of employee information. If the organization decided to fragment...
Q.Consider an organization that maintains a table of employee information. If the organization decided to fragment the employee tables, which of the tables will probably also need to be fragmented? a) Employee-Department links b) Department budgets c) Department-Project ownership d) Insurance policy data
The following information pertains to the payrolls of Warrs Company for November 2018: Employees       Wage earned...
The following information pertains to the payrolls of Warrs Company for November 2018: Employees       Wage earned               Wage earned               Federal Income           State/local                         By 10/31/2018 in November 2018     Tax                              Income Taxes Jane                 $105,000                     $12,000                       $1,500                         $650 Tom                     60,000                      7,000 500 250 Bill                        6,000 1,200                          0                                   0 Actual state unemployment tax rate is 4%, while the federal unemployment tax rate is 1%. The taxable income limit for social security tax...
in c++ you need to write a program that maintains the gradebook for a specific course....
in c++ you need to write a program that maintains the gradebook for a specific course. For each student registered in this course, the program keeps track of the student’s name, identification number (id), four exam grades, and final grade. The program performs several functionalities such as: enrolling a student in the course, dropping a student from the course, uploading student’s exam grades, displaying the grades of a specific student, displaying the grades of all students in the course, and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT