Question: Please help me with this code: //Person class public class Person { private String firstName; private String lastName; public String getFirstname() { return firstName; }

 Please help me with this code: //Person class public class Person

Please help me with this code:

//Person class

public class Person { private String firstName; private String lastName; public String getFirstname() { return firstName; } public String getLastname() { return lastName; } public Person(String first, String last) { firstName = first; lastName = last; } public Person(Person copy) { //create new instance Person newPerson = new Person(); //copy instance values //return copy return newPerson; }

}

========================================

//Test class

public class Test { public static void main(String[] args) { // Create new Person Objects Person person1 = new Person("Brianna", "Reha"); Person person2 = new Person("Justine", "Reha"); Person person3 = new Person(person1); System.out.println(person1.toString(true)); System.out.println(person2.toString(false)); System.out.println(person3.toString()); //Test Object equality if(person1 == person2) { System.out.println("These persons are identical using =="); } else { System.out.println("These persons are not identical using =="); } if(person1.equals(person2)) { System.out.println("These persons are identical using equals()"); } else { System.out.println("These persons are NOT identical"); } if(person1.equals(person3)) { System.out.println("These persons are identical"); } else { System.out.println("These persons are NOT identical"); } }

}

Part 3: How to Compare Person Objects Goal In this activity you will learn how compare objects and print objects in Java by overriding the equals()and toString() methods. The following are the tasks you need to complete for this activity: Execution Execute this assignment according to the following guidelines. 1. Create a Person class: a. Create a new Java Project named assignment.. b. Create a new Java Class named Person in the assignment package. c. Create two private String class variables for firstName and lastName with getter methods. d. Create a nondefault constructor that initializes the firstName and lastName class variables. e. Create a copy constructor that initializes the firstName and lastName class variables. 2. Create Test class: a. Create a Test class with a main that is in the assignment package. b. In main(), create two instances of a Person with the same first and last name. c. In main(), create a third Person using a copy constructor with the first person. d. Compare the two Testava X Person Java objects using the 1 package assignment; == operator and 3 public class Test print the results of 4 5 public static void main(String args) the comparison to 6 { 7 // Create new Person Objects the system console. 8 Person personi - nen Person("Brionna", "Reha"): 9 Person person2 - new Person("Justine", "Reha"): 10 Person person new Person personi): 11 12 // Test Object equality 13 if(person person2) System.out.println("These persons are identical using -'); else System.out.println("These persons are not identical using -"); 17 15 16 e. Compare the two objects using the equals() and print the results of the comparison to the system console. 2021. Grand Canyon University. All Rights Reserved. 12 GRAND CANYON UNIVERSITY f. Compare the first and third person using the equals() and print the results of the comparison to the system console. g. Print the two objects using the toString() to the system console. h. Run the Test class. Take a screen shot of the output. i. Provide a brief, three-to four-sentence description of how and why the output was displayed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!