(Solved) : Modification 1 Constructor 5 Parameters Well Setdoctorid Method Id Parameter Less Equal Ze Q37256195 . . .
Modification 1: In the constructorthat has 5 parameters, as well as in the setDoctorIDmethod, if the id parameter is less than or equal to zero,throw an IllegalArgumentException. The message for theexception would be: “Doctor ID must be a positive number.”
Modification 2: In the constructorthat has 5 parameters, as well as in thesetYearsOfExperience method, if the yearsparameter is less than or equal to zero, throw anIllegalArgumentException. The message for the exceptionwould be: “The number of years of experience must be a positivenumber.”
Modification 3: Update the javadoccomments to include the @exception tag for the constructor, thesetDoctorID method, and the setYearsOfExperiencemethod.
package medical_system;
import java.util.Objects;
/**
* This class represents a doctor in the medical system.
* @author Mayelin Felipe
*/
public class Doctor extends Person
{
// instance variables
private int doctorID;
private String medSchool;
private int yearsOfExperience;
/**
* This constructor initializes the fields to the passedvalues.
* @param first Doctor’s first name.
* @param last Doctor’s last name.
* @param id Doctor’s id.
* @param school Doctor’s medical school.
* @param years Doctor’s years of experience.
*/
public Doctor(String first, String last, int id, String school, intyears)
{
super(first, last);
doctorID = id;
medSchool = school;
yearsOfExperience = years;
}
/**
* This is a copy constructor. It initializes the fields of theobject being
* created to the same values as the fields in the object passed asan argument.
* @param doctorObject The object being copied.
*/
public Doctor(Doctor doctorObject)
{
super(doctorObject);
if( doctorObject != null )
{
doctorID = doctorObject.doctorID;
medSchool = doctorObject.medSchool;
yearsOfExperience = doctorObject.yearsOfExperience;
}
}
/**
* The getDoctorID method returns a Doctor’s id.
* @return The value in the doctorID field.
*/
public int getDoctorID()
{
return doctorID;
}
/**
* The getMedSchool method returns the name of the medical schoolattended by the doctor.
* @return The value in the medSchool field.
*/
public String getMedSchool()
{
return medSchool;
}
/**
* The getYearsOfExperience method returns the years of experiencethe doctor has.
* @return The value in the yearsOfExperience field.
*/
public int getYearsOfExperience()
{
return yearsOfExperience;
}
/**
* The setDoctorID method stores a value in the doctorIDfield.
* @param id the value to store in doctorID.
*/
public void setDoctorID(int id)
{
doctorID = id;
}
/**
* The setMedSchool method stores a value in the medSchoolfield.
* @param school the value to store in medSchool.
*/
public void setMedSchool(String school)
{
medSchool = school;
}
/**
* The setYearsOfExperience method stores a value in theyearsOfExperience field.
* @param years the value to store in yearsOfExperience.
*/
public void setYearsOfExperience(int years)
{
yearsOfExperience = years;
}
/**
* The toString method returns a string representing the state of aDoctor object.
* @return A string containing the doctor’s information: first name,last name,
* id, school attended, and years of experience.
*/
@Override
public String toString()
{
return super.toString() + String.format(“n%-30s %s n%-30s %sn%-30s %s”,
“Doctor ID:”, doctorID,
“Graduated From:”, medSchool,
“Years of Experience:”, yearsOfExperience);
}
/**
* The equals method compares two Doctor objects. The result is trueif the
* argument is not null and is a Doctor object with the same valuesfor all
* fields as the calling object.
* @param obj The object to compare the calling Doctor objectwith.
* @return true if the given object has the same value for allfields except the id.
*/
@Override
public boolean equals(Object obj)
{
if( !(obj instanceof Doctor))
return false;
// we already know that obj is of type Doctor, so it’s safe tocast
Doctor doctor = (Doctor) obj;
// return true or false depending on whether firstName,lastName, medSchool, and
// yearsOfExperience have the same value.
return super.equals(doctor) &&medSchool.equals(doctor.medSchool)
&& yearsOfExperience == doctor.yearsOfExperience;
}
/**
* The hashCode method calculates a Doctor’s hashcode based on itsdata.
* @return An int value calculated based on the object’sfields.
*/
@Override
public int hashCode() {
int hash = 7;
hash = 23 * hash + Objects.hashCode(this.medSchool);
hash = 23 * hash + this.yearsOfExperience;
return super.hashCode() + hash;
}
}
Expert Answer
Answer to Modification 1: In the constructor that has 5 parameters, as well as in the setDoctorID method, if the id parameter is l…
OR