Design an Employee class . Should have member variables: Employee Name and Emplo
ID: 3545558 • Letter: D
Question
Design an Employee class. Should have member variables: Employee Name and
Employee Number. Write the appropriate constructors, accessors, and mutators
for the class. Demonstrate (and test) all methods for the class.
Design a ProductionWorker class that is derived from the Employee class.
It should have member variables: Shift and Hourly Pay Rate.
The day shift is Shift 1 and the night shift is Shift 2. Write the appropriate constructors,
accessors, and mutators for the class. Demonstrate (and test) all methods for the class.
Design a ShiftSupervisor class that is derived from the Employee class.
A shift supervisor is a salaried employee who supervises a shift. In addition he earns a
yearly bonus when his shift meets production goals. Write the appropriate constructors,
accessors, and mutators for the class. Demonstrate (and test) all methods for the class.
Design a TeamLeader class that extends the ProductionWorker class.
A team leader is a production worker who leads a small team. In addition to hourly pay,
they earn a fixed monthly bonus. Also they are required to attend a minimum number of
hours of training per year. Write the appropriate constructors, accessors, and mutators for
the class. Demonstrate (and test) all methods for the class.
Design a Salesman class. A salesman is an employee who earns his pay based on the
percent of sales. For example, if he sold $100,000 in merchandise, he earns $5000 based
on a 5.0 percent commission rate. Write the appropriate constructors, accessors, and
mutators for the class. Demonstrate (and test) all methods for the class.
Design a SalesAssociate class. A sales associate is a beginner salesman who earns his
pay based on a Base Salary plus a reduced commission rate for all sales over a Base
Sales Quota. For example, assume a sales associate had a base salary of $2000,
a base sales quota of $40,000, and commission rate of 3 percent. If he sold $100,000
in merchandise, he earns $3800. Write the appropriate constructors, accessors, and
mutators for the class. Demonstrate (and test) all methods for the class.
Explanation / Answer
import java.util.*;
public class Employee
{
String name; // Employee name
String employeeNumber; // Employee number
String hireDate; // Employee hire date
public Employee(String n, String e, String h)
{
name = n;
employeeNumber = e;
hireDate = h;
}
public Employee()
{
name = "";
employeeNumber = "";
hireDate = "";
}
public void setName(String n)
{
name = n;
}
public void setEmployeeNumber(String e)
{
if (isValidEmpNum(e))
{
employeeNumber = e;
}
else
{
employeeNumber = "";
}
}
public void setHireDate(String h)
{
hireDate = h;
}
public String getName()
{
return name;
}
public String getEmployeeNumber()
{
return employeeNumber;
}
public String getHireDate()
{
return hireDate;
}
private boolean isValidEmpNum(String e)
{
boolean status = true;
if (e.length() != 5)
status = false;
else
{
if ((!Character.isDigit(e.charAt(0))) ||
(!Character.isDigit(e.charAt(1))) ||
(!Character.isDigit(e.charAt(2))) ||
(e.charAt(3) != '-') ||
(!Character.isLetter(e.charAt(4))) ||
//needs to check if between A and M
(!(e.charAt(4)>= 'A' && e.charAt(4)<= 'M')))
{
status = false;
}
}
return status;
}
public String toString()
{
String str = "Name: " + name + " Employee Number: ";
if (employeeNumber == "")
{
str += "INVALID EMPLOYEE NUMBER";
}
else
{
str += employeeNumber;
}
str += (" Hire Date: " + hireDate);
return str;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.