Question: Recall the class discussion about object composition. In that discussion we looked at several objects: Date, Time, Name, Employee, and Company. Using the given source
Recall the class discussion about "object composition". In that discussion we looked at
several objects: Date, Time, Name, Employee, and Company. Using the given source code for
these classes, complete the following three methods whose stubs are provided for you in the
Programjava file.
int findLargestSalary Employee workers This method returns the salary of the
worker in the given parameter array who is paid the most. Your method should only require
linear time ie On since the problem can be solved using a single loop.
int countLeapDay Employee workers This method returns the number of workers in
the given parameter array who were born on Leap Day February Your method should
only require linear time ie since the problem can be solved using a single loop.
int busiestHiringYear Employee workers This method returns the year in which the
most number of workers were hired. If there is a tie for the value of this year, then any year
that is busiest may be returned that is you can break the tie any way you wish As always,
we want as efficient a solution as possible. The best strategy for this problem is to first sort
the array of Employees. You want to sort the array based on the hireDate not alphabetically
by name Once the array is sorted, then you can do a single loop through the array, locating
each consecutive sequence of array entries that have the same hireDate. You can use the
library method Arrays.sortworkers but you will need to add a compareTo method
to the given Employee class. You will also need to edit the header of the Employee class
from:
public class Employee
to
public class Employee implements Comparable Employee
You must not change the given Date, Name or Employee classes in any other way. A
Programjava file is provided for you. The main method in this class creates Employee
arrays, and invokes the methods above. If your class is written correctly then you should
have no error messages when this main method executes. Note that testing can reveal the
presence of errors, but the lack of errors in the testing process does not guarantee that the
code is correct. You may want to add more test cases to the given main method. Upload a
zipfile containing all of the files: Programjava, Employee.java, Name.java, and Date.java.
You should include YOUR NAME in the comment at the top of every file.source code for program
Program
@author PUT YOUR NAME HERE
import java.util.Arrays;
public class Program
public static void main String args
System.out.println "Hello world" ;
Employee people
new Employee new Name bob"doe" new Date new Date
new Employee new Name alice"evans"new Date new Date
new Employee new Name ann"lee" new Date new Date
new Employee new Name sam"kim" new Date new Date
new Employee new Name jane"lee" new Date new Date
new Employee new Name ed"smith" new Date new Date
new Employee new Name ted"jones" new Date new Date
;
Employee folks
new Employee new Name bob"doe" new Datenew Date
new Employee new Name alice"evans"new Datenew Date
new Employee new Name ann"lee" new Date new Date
new Employee new Name sam"kim" new Date new Date
new Employee new Name jane"lee" new Datenew Date
new Employee new Name ed"smith" new Datenew Date
new Employee new Name ted"jones" new Datenew Date
;
Employee individual
new Employee new Name alice"evans" new Date new Date
;
try
if findLargestSalary people
System.out.println "findLargestSalary fails on output ;
catch RuntimeException trouble
System.out.println "Error in findLargestSalary method" ;
try
if findLargestSalary folks
System.out.println "findLargestSalary fails on output ;
catch RuntimeException trouble
System.out.println "Error in findLargestSalary method" ;
try
if findLargestSalary individual
System.out.println "findLargestSalary fails on output ;
catch RuntimeException trouble
System.out.println "Error in findL
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
