Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add a public getEmployee method that accepts an integer index and then returns the Employee object found at that index in the collection of employees.

Add a public getEmployee method that accepts an integer index and then returns the Employee object found at that index in the collection of employees. Do not forget to add and enforce the precondition(s) on the index. Write unit tests for getEmployee: 1. Any and all precondition checks 2. Border conditions on the parameter 3. Finding the first, last, and middle employee

public class Employee {

private String name;

private int yearOfHire;

private String jobTitle;

private double hourlyWage;

private int rating;

private static final double MINIMUM_WAGE = 7.25;

/**

* Employee default constructor

*

* @precondition none

* @postcondition this.yearOfHire = 1970 && this.hourlyWage = MINIMUM_WAGE

* && this.rating = 1 && this.name == null && this.jobTitle

* == null

*

*

*/

public Employee() {

this.yearOfHire = 1970;

this.hourlyWage = MINIMUM_WAGE;

this.rating = 1;

this.name = null;

this.jobTitle = null;

}

/**

* initializes Employee with specific values.

*

* @precondition name !=null && name.isEmpty()==false. jobTitle !=null &&

* jobTitle.isEmpty()==false. yearOfHire >= 1970. hourlyWage

* >= MIN_WAGE. rating >=1 && rating <= 5.

* @postcondition getName()=name && getYearOfHire()=yearOfHire &&

* getJobTitle()= jobTitle && getHourlyWage()= hourlyWage &&

* getRating()= rating.

* @param name name of employee

* @param yearOfHire year employee got hired

* @param jobTitle title of job

* @param hourlyWage employees hourly wage

* @param rating rating of employee

*

*/

public Employee(String name, int yearOfHire, String jobTitle, double hourlyWage, int rating) {

if (name == null) {

throw new IllegalArgumentException("name cannot be null");

}

if (name.isEmpty()) {

throw new IllegalArgumentException("name cannot be empty");

}

if (rating < 1 || rating > 5) {

throw new IllegalArgumentException("rating must be between 1 and 5 inclusive");

}

this.name = name;

this.yearOfHire = yearOfHire;

this.jobTitle = jobTitle;

this.hourlyWage = hourlyWage;

this.rating = rating;

}

/**

* Gets the name of the Employee.

*

*

* @return the name of the Employee

*/

public String getName() {

return this.name;

}

/**

* Gets year of hire for the employee.

*

* @return the year that the employee was hired.

*/

public int getYearOfHire() {

return this.yearOfHire;

}

/**

* Gets the hourly wage for the employee.

*

* @return the hourly wage for the employee.

*/

public double getHourlyWage() {

return this.hourlyWage;

}

/**

* Sets the hourly wage for the employee.

*

* @precondition hourlyWage >= MIN_WAGE

* @postcondition gethourlyWage()=hourlyWage

*

* @param hourlyWage

* The hourlyWage for the employee

*/

public void setHourlyWage(double hourlyWage) {

if (hourlyWage < MINIMUM_WAGE) {

throw new IllegalArgumentException("HourlyWage should be MINIMUM_WAGE");

}

this.hourlyWage = MINIMUM_WAGE;

}

/**

* Gets the job title.

*

* @return the job title.

*/

public String getJobTitle() {

return this.jobTitle;

}

/**

* Sets the job title.

*

* @precondition jobTitle != null && jobTitle.isEmpty()==false.

* @postcondition getjobTitle()= jobTitle

*

* @param jobTitle

* The jobTitle for the employee

*

*/

public void setJobTitle(String jobTitle) {

if (jobTitle == null) {

throw new IllegalArgumentException("Job title cannot be null");

}

if (jobTitle.isEmpty()) {

throw new IllegalArgumentException("Job title cannot be empty");

}

this.jobTitle = jobTitle;

}

/**

* Gets the rating.

*

* @return the rating

*/

public int getRating() {

return this.rating;

}

/**

* Sets the rating.

*

* @precondition rating >=1 && rating <= 5

* @postcondition getRating()= rating

*

* @param rating

* The rating of the employee

*/

public void setRating(int rating) {

if (rating < 1 || rating > 5) {

throw new IllegalArgumentException("Rating must be between 1 and 5 inclusively");

}

this.rating = rating;

}

@Override

public String toString() {

return "Employee [name=" + name + ", yearOfHire=" + yearOfHire + ", jobTitle=" + jobTitle + ", hourlyWage="

+ hourlyWage + ", rating=" + rating + "]";

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions