The SalesCenter application stores information about three employees. There is o
ID: 3794676 • Letter: T
Question
The SalesCenter application stores information about three employees. There is one manager (Diego Martin, salary $55,000), and two associates (Kylie Walter earning 18.50 per hour and Michael Rose earning $16.75 per hour). SalesCenter should be able to display the name and title for a specified employee. Additionally, the SalesCenter application should calculate and display the pay for a specified employee based on the pay argument entered by the user. The pay argument is hours worked if the pay is for an associate. The pay argument is number of weeks if the manager pay is to be calculated.
The SalesCenter interface provides a menu of options. Depending on the option, additional input may be required. An example of the inputs and outputs below:
EmployeePayQuit
Enter choice: E
Enter employee number (1, 2, or 3): 2
Kylie Walter, associate
EmployeePayQuit
Enter choice: P
Enter employee number (1, 2, or 3): 2
Enter the hours for associate or pay period for manger: 40
Kylie Walter, associate
$740.00
EmployeePayQuit
Enter choice: Q
The SalesCenter application can be modeled with objects for a manager and two associates. The manager and associate objects are both employee objects. Therefore, an Employee abstract class is a superclass for subclasses Manager and Associate. The Employee class should define an employee’s first and last name, and include an abstract class for calculating pay. A manager’s pay is based on a pay period specified in weeks. Associates pay is by the hour. The abstract pay() method in Employee will be overridden in Manager and Associate.
The SalesCenter class designs are:
Employee
firstName
lastName
+ Employee(fName: string, lName: string)
+ pay(period: double) //abstract class; should return employee pay for specified period
+toString() // returns a string with employee first and last names
Manager (extends Employee)
yearlySalary
+Manager(fName: string, lName: string, sal: double)
+getSalary() : double // returns the yearly salary
+pay(weeks: double) : double // returns amount earned based on the annual salary / 52
+toString() // returns a string with the employee name and title (manager)
Associate (extends Employee)
hourlyPayRate
+Associate(fname: string, lName: string, rate: double)
+getRate() : double // returns the hourly pay rate
+pay(hours: double) : double // returns the amount earned based on hourly rate and hours worked
+toString() // returns a string with employee name and title (associate)
Your task is to write the Employee, Manager, and Associate classes for the SalesCenter application and then the SalesCenter test code to use the classes. The SalesCenter code is shown below:
/*
* Name:
* Date:
* SalesCenter Application
* A sales center with managers and associates.
<insert application description here>
*/
import java.util.Scanner;
import java.text.NumberFormat;
public class SalesCenter {
/**
* Displays employee name and pay.
*/
public static void payEmployee(Employee emp, double payArg) {
NumberFormat money = NumberFormat.getCurrencyInstance();
double pay;
System.out.println(emp);
pay = emp.pay(payArg);
System.out.println(money.format(pay));
}
public static void main(String[] args) {
Manager emp1 = new Manager("Diego","Martin", 55000);
Associate emp2 = new Associate("Kylie", "Walter", 18.50);
Associate emp3 = new Associate("Michael", "Rose", 16.75);
Scanner input = new Scanner(System.in);
String action;
int empNum;
double payArg;
Employee emp = emp1; //set to default emp1
/* display menu of choices */
do {
System.out.println(" Employee\Pay\Quit");
System.out.print("Enter choice: ");
action = input.next();
if (!action.equalsIgnoreCase("Q")) {
System.out.print("Enter employee number (1, 2, or 3):");
empNum = input.nextInt();
switch (empNum) {
case 1: emp = emp1; break;
case 2: emp = emp2; break;
case 3: emp = emp3; break;
}
if (action.equalsIgnoreCase("E")) {
System.out.println(emp);
} else if (action.equalsIgnoreCase("P")) {
System.out.print("Enter the hours for associate or pay period for manager: ");
payArg = input.nextDouble();
payEmployee(emp, payArg);
}
}
} while (!action.equalsIgnoreCase("Q"));
}
}
Test the program to ensure it works properly, testing all the employees and a variety of pay scenarios. Be sure to capture the screen output to submit with your assignment. Be sure to include the class UML diagrams as comment lines in your class definitions.
Explanation / Answer
Hi, Please find my implementation.
Please let me know in case of any issue.
########### Employee.java #########################
public abstract class Employee {
private String firstName;
private String lastName;
public Employee(String fName, String lName){
firstName = fName;
lastName = lName;
}
public abstract double pay(double period); //abstract class; should return employee pay for specified period
public String toString(){ // returns a string with employee first and last names
return "Firat Name : "+firstName+", Last Name: "+lastName;
}
}
########### Manager.java #########################
public class Manager extends Employee{
private double yearlySalary;
public Manager(String fName, String lName, double sal){
super(fName, lName);
yearlySalary = sal;
}
public double getSalary(){ // returns the yearly salary
return yearlySalary;
}
public double pay(double weeks){ // returns amount earned based on the annual salary / 52
return weeks*(yearlySalary/12.0);
}
public String toString(){ // returns a string with the employee name and title (manager)
return super.toString()+", and Title : Manager";
}
}
########### Associate.java #########################
public class Associate extends Employee{
private double hourlyPayRate;
public Associate(String fname, String lName, double rate){
super(fname, lName);
hourlyPayRate = rate;
}
public double getRate() { // returns the hourly pay rate
return hourlyPayRate;
}
public double pay(double hours) { // returns the amount earned based on hourly rate and hours worked
return hours*hourlyPayRate;
}
public String toString(){ // returns a string with employee name and title (associate)
return super.toString()+", and Title : Associate";
}
}
########### SalesCenter.java #########################
import java.util.Scanner;
import java.text.NumberFormat;
public class SalesCenter {
/**
* Displays employee name and pay.
*/
public static void payEmployee(Employee emp, double payArg) {
NumberFormat money = NumberFormat.getCurrencyInstance();
double pay;
System.out.println(emp);
pay = emp.pay(payArg);
System.out.println(money.format(pay));
}
public static void main(String[] args) {
Manager emp1 = new Manager("Diego","Martin", 55000);
Associate emp2 = new Associate("Kylie", "Walter", 18.50);
Associate emp3 = new Associate("Michael", "Rose", 16.75);
Scanner input = new Scanner(System.in);
String action;
int empNum;
double payArg;
Employee emp = emp1; //set to default emp1
/* display menu of choices */
do {
System.out.println(" Employee\Pay\Quit");
System.out.print("Enter choice: ");
action = input.next();
if (!action.equalsIgnoreCase("Q")) {
System.out.print("Enter employee number (1, 2, or 3):");
empNum = input.nextInt();
switch (empNum) {
case 1: emp = emp1; break;
case 2: emp = emp2; break;
case 3: emp = emp3; break;
}
if (action.equalsIgnoreCase("E")) {
System.out.println(emp);
} else if (action.equalsIgnoreCase("P")) {
System.out.print("Enter the hours for associate or pay period for manager: ");
payArg = input.nextDouble();
payEmployee(emp, payArg);
}
}
} while (!action.equalsIgnoreCase("Q"));
}
}
/*
Sample run:
EmployeePayQuit
Enter choice: P
Enter employee number (1, 2, or 3):2
Enter the hours for associate or pay period for manager: 4
Firat Name : Kylie, Last Name: Walter, and Title : Associate
Rs.74.00
EmployeePayQuit
Enter choice: E
Enter employee number (1, 2, or 3):2
Firat Name : Kylie, Last Name: Walter, and Title : Associate
EmployeePayQuit
Enter choice: P
Enter employee number (1, 2, or 3):1
Enter the hours for associate or pay period for manager: 54
Firat Name : Diego, Last Name: Martin, and Title : Manager
Rs.247,500.00
EmployeePayQuit
Enter choice: Q
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.