Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The objective of the lab is to take the UML Class diagram and enhance last week\

ID: 3641138 • Letter: T

Question

The objective of the lab is to take the UML Class diagram and enhance last week's Employee class by making the following changes:

Create a class called Salaried that is derived from Employee.
Create a class called Hourly that is also derived from Employee.
Since all classes/objects inherit from java.lang.object class, change the "displayClass" information method to override the java.lang.object "toString" method.
Override necessary method(s) in each of the new subclasses as applicable.

Notice the change in UML diagram. It is common practice to leave out the accessors and mutators (getters and setters) from UML class diagrams, since there can be so many of them. Unless otherwise specified, it is assumed that there is an accessor (getter) and a mutator (setter) for every class attribute.

All classes that are contained in Java's API as well as any external classes that you or I may create are derived from the java.lang.object class. The Object class contains several methods which are inherited by all other Java classes. One of these methods is called toString. The toString method can be overridden by any class and its purpose is to display an object’s current state. This type of functionality should sound familiar to you. After all, your displayBenefits method was designed to print the current state of a Benefit object! In this week's lab, we are going to move the logic contained in displayBenefits to the toString method. Take a look at Java’s description of the toString method contained in the Object class and pay particular attention to its return type before moving on.

STEP 4: Modify the Employee Class

Java provides three explicit access modifiers for attributes and methods. So far, we have dealt with two of them: public and private. This week, we will use a new access modifier: protected. Java states that "The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package." For additional information on the use of protected as an access modifier, review the Controlling Access to Members of a Class tutorial.

STEP 5: Create the Salaried Class

In this step, it is necessary to implement constant attributes. As the name implies, constants contain values that do not change. In Java, an attribute is made into a constant by adding the keywords "static final" in the declaration. For additional information on the creation and use of constants, review the Understanding Instance and Class Members tutorial.

One other very important concept to review for this step in the lab is the use of the super method. Super is used to access parent-defined attributes and methods within a subclass. A common practice is to use the code super() or super(arg-list) to invoke the constructor in a parent class. For additional information on the use of super in your application and specifically this week’s constructors, review the Using the Keyword super tutorial.

STEP 6: Create the Hourly Class

STEP 7: Construct the Main Method

STEP 8: Compile and Test

When done, compile and execute your code, and debug any errors until your code is error-free.

Check your output to ensure that you have the desired output, modify your code as necessary, and rebuild.

Your output should resemble the following. Make sure to fully exercise all of your new and overridden subclass methods. This could result in output that is lengthier than the example below.

STEP 4: Modify the Employee Class

Explanation / Answer

employee.java ******************** package employee; import java.text.DecimalFormat; public class Employee { private String firstName; private String lastName; private char gender; private int dependents; public Benefit benefit = new Benefit(); public Benefit getBenefit() { return benefit; } public void setBenefit(Benefit benefit) { this.benefit = benefit; } private double annualSalary; private double weeklySalary; public double getWeeklySalary() { return weeklySalary; } public void setWeeklySalary(double weeklySalary) { this.weeklySalary = weeklySalary; } private static int numEmployees = 0; public Employee() { numEmployees++; } public Employee(String firstName, String lastName, char gender, int dependents, double annualSalary, Benefit benefit) { this.firstName = firstName; this.lastName = lastName; this.gender = gender; this.dependents = dependents; this.annualSalary = annualSalary; this.benefit = benefit; numEmployees++; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public char getGender() { return gender; } public void setGender(char gender) { this.gender = gender; } public int getDependents() { return dependents; } public void setDependents(int dependents) { this.dependents = dependents; } public void setDependents(String dependents) { this.dependents = Integer.parseInt(dependents); } public double getAnnualSalary() { return annualSalary; } public void setAnnualSalary(double annualSalary) { this.annualSalary = annualSalary; } public void setAnnualSalary(String annualSalary) { this.annualSalary = Integer.parseInt(annualSalary); } public static int getNumEmployees() { return numEmployees; } public static void setNumEmployees(int numEmployees) { Employee.numEmployees = numEmployees; } public double calcPay() { return annualSalary; } public String toString() { super.toString(); double annSal = getAnnualSalary(); DecimalFormat formatter = new DecimalFormat("#,###,###"); DecimalFormat decimalFormat = new DecimalFormat("#.##"); String weekSalary = decimalFormat.format(getWeeklySalary()); Benefit benef = getBenefit(); return "*********************Employee Information*********************" +" First Name: " + getFirstName() + " Last Name:= " + getLastName() + " Gender: " + String.valueOf(getGender()) +" Dependents: " + getDependents() +" Annual Salary: $" + formatter.format(annSal) +" Weekly Pay: $" + weekSalary +" Health Insurance : "+benef.getHealthInsurance() +" Life Insurance : "+String.valueOf(benef.getLifeInsurance()) +" Vacation : "+String.valueOf(benef.getVacation()); } public static void main(String args[]) { Employee employee = new Employee(); java.util.Scanner console = new java.util.Scanner(System.in); System.out.println("Please enter Employee's first name"); String tempFName = console.next(); employee.setFirstName(tempFName); System.out.println("Please enter Employee's last name"); String tempLName = console.next(); employee.setLastName(tempLName); System.out.println("Please enter Employee's gender"); String tempGender = console.next(); employee.setGender(tempGender.charAt(0)); System.out.println("Please enter Employee's dependents"); String tempDepend = console.next(); employee.setDependents(tempDepend); System.out.println("Please enter Employee's annual salary"); String tempAnnSal = console.next(); employee.setAnnualSalary(tempAnnSal); System.out.println("Please enter Employee's health Insurance"); String tempHlthInsur = console.next(); employee.benefit.setHealthInsurance(tempHlthInsur); System.out.println("Please enter Employee's Life Insurance"); double tempLifeInsur = console.nextDouble(); employee.benefit.setLifeInsurance(tempLifeInsur); System.out.println("Please enter Employee's vacation details"); int tempVacation = console.nextInt(); employee.benefit.setVacation(tempVacation); employee.setWeeklySalary(Double.parseDouble(tempAnnSal)/52); System.out.println(employee); System.out.println(" Total Employees: "+Employee.numEmployees); Benefit ben = new Benefit("FULL", 1000.0, 5); Salaried salaried = new Salaried("Mary", "Noia", 'F', 5,24000, ben,1); double weekly_pay = salaried.calculatePay(); salaried.setWeeklySalary(weekly_pay); System.out.println(salaried); System.out.println(" Total Employees: "+numEmployees); Benefit ben2 = new Benefit("None", 500.0, 3); String category = "Part-Time"; double annSal = 20.0*20.0*52; Hourly hourly = new Hourly("Frank", "Johnes", 'M', 3, annSal,ben2,20.0,20.0,category ); hourly.setWeeklySalary(annSal/52); System.out.println(hourly); System.out.println(" Total Employees: "+numEmployees); } public double calculatePay() { return 0; } } Hourly.java *************** package employee; public class Hourly extends Employee { static final double MIN_WAGE = 10; static final double MAX_WAGE = 75; static final double MIN_HOURS = 0; static final double MAX_HOURS = 50; static final String[] categoryArray = {"temporary", "part time","full time"}; private double wage; private double hours; private String category; public Hourly(){ super(); } public Hourly(double wage, double hours, String category){ super(); this.wage= wage; this.hours = hours; this.category = category; } public Hourly(String firstName, String lastName, char gender, int dependents, double annualSalary, Benefit benefit,double wage, double hours, String category){ super(firstName,lastName,gender,dependents,annualSalary,benefit); this.wage= wage; this.hours = hours; this.category = category; } public String toString(){ String str = super.toString(); return str + " Category :"+category; } public double getWage() { return wage; } public void setWage(double wage) { if(wage>=10&& wage
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote