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

Finish the following Employee class public class Employee { private Person perso

ID: 3642419 • Letter: F

Question

Finish the following Employee class

public class Employee {

private Person person;

public Person getPerson(){
//complete this section

}
public void setPerson(Person p) {
//complete this section with validation


}
protected Employee (Person p) throws Exception{
//complete this section with validation

}
private Employee(){//do not alter


}
}


this is the Person class mentioned in the Person method

public class Person {


private String firstName;
private String lastName;

public String getFirstName(){

return firstName;

}
public String getLastName(){

return lastName;

}

public void setLastName (String lastNameChange){
if (lastName != null && lastName.length() > 0) {
this.lastName = lastNameChange;
}
}
public Person (String firstName, String lastName) throws Exception{
if (firstName == null || firstName.length() == 0) {
throw new Exception("Bad entry for first name");

}
}
private Person(){
}
}

Explanation / Answer

public class Employee { private Person person; public Person getPerson(){ if(person == null) throw new Exception("ERROR: Could not get person.") return person; } public void setPerson(Person p) { if(p != null) { if(person != null) { if(p.getFirstName() != null && p.getFirstName().length() > 0) person.setFirstName( p.getFirstName() ); else throw new Exception("ERROR: Bad first name") if(p.getLastName() != null && p.getLastName().length() > 0) person.setLastName( p.getLastName() ); else throw new Exception("ERROR: Bad last name"); } else person = new Person(p.getFirstName(), p.getLastName()); } else throw new Exception("ERROR: Bad person"); } protected Employee (Person p) throws Exception{ if(p != null) setPerson(p); else throw new Excption("ERROR: Could not create new person") } private Employee(){//do not alter } } public class Person { private String firstName; private String lastName; public String getFirstName(){ return firstName; } public String getLastName(){ return lastName; } public void setLastName (String lastNameChange){ if (lastName != null && lastName.length() > 0) { this.lastName = lastNameChange; } } public Person (String firstName, String lastName) throws Exception{ if (firstName == null || firstName.length() == 0) { throw new Exception("Bad entry for first name"); } } private Person(){ } }

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