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

person class: public class Person { private String firstName, lastName,SSN; priv

ID: 3710213 • Letter: P

Question

person class:

public class Person {
   private String firstName, lastName,SSN;
   private boolean access;
   public Person(){
      
   }
   public Person(String f, String l, String ssn, boolean a) {
       this.firstName=f;
       this.lastName=l;
       this.access=a;
       this.SSN=ssn;
   }
   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 String getSSN() {
       return SSN;
   }
   public void setSSN(String sSN) {
       SSN = sSN;
   }
   public boolean isAccess() {
       return access;
   }
   public void setAccess(boolean access) {
       this.access = access;
   }
  
}

Using the Person class from the previous part, design the following methods. (5 points each, 15 points total) d. toString0 2. equals(Person per) 3. Copy constructor

Explanation / Answer

public class Person {

private String firstName, lastName,SSN;

private boolean access;

public Person(){

  

}

public Person(String f, String l, String ssn, boolean a) {

this.firstName=f;

this.lastName=l;

this.access=a;

this.SSN=ssn;

}

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 String getSSN() {

return SSN;

}

public void setSSN(String sSN) {

SSN = sSN;

}

public boolean isAccess() {

return access;

}

public void setAccess(boolean access) {

this.access = access;

}

//The toString Method

public String toString() {

//initialize an empty String

String name = "";

//use the getter methods to retreive the full name

name = this.getFirstName() +" "+this.getLastName();

//return the name

return name;

}

//the equals method

public boolean equals(Person per) {

boolean output = false;

//two persons are same, if they have identical SSN numbers

if(this.getSSN() == per.getSSN()) {

//OPTIONAL, if you really want to check both the person has same name

// if(this.toString() == per.toString()) {

// output = true;

// }

output = true;

}

//return the output

return output;

}

//The copy Constructor

Person(Person p) {

//The Copy Constructor

this.firstName=p.getFirstName();

this.lastName=p.getLastName();

this.access=p.access;

this.SSN=p.getSSN();

}

public static void main(String[] args) {

Person p = new Person("XYZ", "ABC", "50044616", true);

Person per = new Person("XYZ", "ABC", "50044616", true);

System.out.println(p.toString());

System.out.println(p.equals(per));

Person np = new Person(p);

System.out.println(np.toString());

}

  

}

OUTPUT:

XYZ ABC
true
XYZ ABC

Please feel free to comment and ask if you need further help. Hope this helps!