Java Programming Consider the following UML which represents various types of em
ID: 669787 • Letter: J
Question
Java Programming
Consider the following UML which represents various types of employees that might be employed at a particular company. This uses a pay method to pay a set of employees of various types. The invocation of pay method is polymorphic because each class has its own version of the pay method. Do the following for this program. 1) Create the Employee class using the information in UML diagram and the code below. 2) Develop the pay method for the StaffMember class. 3) Modify this program such that all employees can be given different vacation options depending on their classification. 4) Modify the driver program to demonstrate this new functionality.
//********************************************************************
// Firm.java
/ /
/ / Demonstrates polymorphism via inheritance.
//********************************************************************
public class Firm {
//-----------------------------------------------------------------
// Creates a staff of employees for a firm and pays them.
//-----------------------------------------------------------------
public static void main (String[] args) {
Staff personnel = new Staff(); personnel.payday();
}
}
//********************************************************************
// Staff.java
//
// Represents the personnel staff of a particular business. //********************************************************************
private StaffMember[] staffList;
public Staff ()
{
staffList = new StaffMember[6];
staffList[0] = new Executive ("Tony", "123 Main Line","555-0469", "123-45-6789", 2423.07);
staffList[1] = new Employee ("Paulie", "456 Off Line","555-0101", "987-65-4321", 1246.15);
staffList[2] = new Employee ("Vito", "789 Off Rocker", "555-0000", "010-20-3040", 1163);
staffList[3] = new Hourly ("Michael", "678 Fifth Ave.", "555-0690", "958-47-3625", 10.55);
staffList[4] = new Volunteer ("Adrianna", "987 Babe Blvd.", "555-8374");
staffList[5] = new Volunteer ("Benny", "321 Dud Lane", "555-7282");
((Executive)staffList[0]).awardBonus (500.00);
((Hourly)staffList[3]).addHours (40);
}
public void payday ()
{
double amount;
for (int count=0; count < staffList.length; count++)
{
System.out.println (staffList[count]);
amount = staffList[count].pay(); // polymorphic
if (amount == 0.0)
System.out.println ("Thanks!");
else
System.out.println ("Paid: " + amount);
System.out.println ("-----------------------------------");
}
}
//********************************************************************
// StaffMember.java
//
// Represents a generic staff member.
//********************************************************************
public class StaffMember
{
protected String name;
protected String address;
protected String phone;
//-----------------------------------------------------------------
// Constructor: Sets up this staff member using the specified
// information.
//-----------------------------------------------------------------
public StaffMember (String eName, String eAddress, String ePhone)
{
name = eName;
address = eAddress;
phone = ePhone;
}
//-----------------------------------------------------------------
//
Returns a string including the basic employee information.
//-----------------------------------------------------------------
@Override
public String toString()
{
String result = "Name: " + name + " ";
result += "Address: " + address + " ";
result += "Phone: " + phone;
return result;
}
//-----------------------------------------------------------------
// define a pay method for employee.
//-----------------------------------------------------------------
public double pay(){
//ToDo
}
}
//********************************************************************
// Volunteer.java
//
// Represents a staff member that works as a volunteer. //********************************************************************
public class Volunteer extends StaffMember
{
//-----------------------------------------------------------------
// Constructor: Sets up this volunteer using the specified
// information.
//-----------------------------------------------------------------
public Volunteer (String eName, String eAddress, String ePhone)
{
super (eName, eAddress, ePhone);
}
//-----------------------------------------------------------------
// Returns a zero pay value for this volunteer.
//-----------------------------------------------------------------
public double pay()
{
return 0.0;
}
}
//********************************************************************
// Executive.java
//
// Represents staff member that works as an Employee. //********************************************************************
public class Employee extends StaffMember
{
//ToDo
}
//********************************************************************
// Executive.java
//
// Represents an executive staff member, who can earn a bonus. //********************************************************************
public class Executive extends Employee
{
private double bonus;
//-----------------------------------------------------------------
// Constructor: Sets up this executive with the specified
// information.
//-----------------------------------------------------------------
public Executive (String eName, String eAddress, String ePhone, String socSecNumber, double rate)
{
super (eName, eAddress, ePhone, socSecNumber, rate);
bonus = 0; // bonus has yet to be awarded
}
//-----------------------------------------------------------------
// Awards the specified bonus to this executive.
//-----------------------------------------------------------------
public void awardBonus (double execBonus)
{
bonus = execBonus;
}
//-----------------------------------------------------------------
// Computes and returns the pay for an executive, which is the
// regular employee payment plus a one-time bonus.
//-----------------------------------------------------------------
@Override public double pay()
{
double payment = super.pay() + bonus;
bonus = 0;
return payment;
}
}
b. Answer the following questions in a separate sheet, use a “doc” or other text formats:
1. Have the exercise above required you to implement a software design specification for an appropriate development environment.
a. True
b. False
2. Will the exercise allow you to acquire instruction on the proper documentation of source code? If not do you think that you need to provide it anyway.
a. True
b. False (If not do you think that you need to provide it for any implementation & design of any software.)
4. Provide an example that you have acquired the knowledge to design and apply relevant software testing procedures.
Firm +main(args: StringD: void StaffMember Staff #name : String #address : String #phone : String staffList:StaffMember +payday0:void +toString0: String +payo: double Volunteer Employee #sociaisecutiryNumber : String #payRate : double +pay0: double +toString0: String +pay0: double Executive Hourly -bonus : double -hoursWorked: int +awardBonus(execBonus: double): void +pay0: double +addHours(moreHours: int): void +pay0: double +toString0: StringExplanation / Answer
public class Employee extends StaffMember
{
char *EmployeeName;
int Age;
char *DateOfJoing, Department;
}
public double pay(double GrossPay, double NetPay, double Tax, double superAnnuationContribtion){
double GrossPay, NetPay, Tax, superAnnuationContribtion;
GrossPay = HoursWorked * HourlyRate;
NetPay = GrossPay - Tax - superAnnuationContribtion;
cout << NetPay;
}
public class Employee extends StaffMember
{
int age;
char EmployeeName[40];
char *SocialSecurityNumber;
double payRate;
String toString(); // a member function
double pay(); // member function to calculate the gross and net pay
}
class leave {
int numOfDaysOfLeavePerYear; // 30 days per year or 2.5 days per calendar month
int leaveAlreadyAvailed, leaveCarriedOverToTheNextYear;
int numberOfDaysWorked;
int leaveBalance;
leaveBalance = numberOfDaysWorked * 2.5 / 30;
cout << "Leave available = " << leaveBalance << " days ";
}
1.b]
Yes, the exercise above required me to implement a software design specification for an appropriate development environment. I have used the Function Point Analysis to estimate the time complexity.
2. ]
Yes, the exercise allowed me to acquire instruction on the proper documentation of source code, like comments, logical flow, description of each function, input and output parameters etc
4.] An example to demonstrate that I have acquired the required knowledge to design and apply relevant software testing procedures.
There are many types of testing like given below:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.