Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming public class Person { private String firstName; //store the first name private String lastName; //store the last name //Default constructor //Initialize firstName and

Java Programming

public class Person { private String firstName; //store the first name private String lastName; //store the last name //Default constructor //Initialize firstName and lastName to an empty string. //Postcondition: firstName = ""; lastName = ""; public Person() { firstName = ""; lastName = ""; } //Constructor with parameters //Set firstName and lastName according to the parameters. //Postcondition: firstName = first; lastName = last; public Person(String first, String last) { setName(first, last); } //Method to output the first name and last name //in the form firstName lastName. public String toString() { return (firstName + " " + lastName); } //Method to set firstName and lastName according to //the parameters. //Postcondition: firstName = first; lastName = last; public void setName(String first, String last) { firstName = first; lastName = last; } //Method to return firstName. //Postcondition: The value of firstName is returned. public String getFirstName() { return firstName; } //Method to return lastName. //Postcondition: The value of lastName is returned. public String getLastName() { return lastName; } } 

a) Read the class Person to store the name of a person. As we can see that the methods we included merely set the name and print the name of a person. Redefine the class person so that, in addition to what existing Class does, you can

Set the last name only.

Set the first name only.

Set the middle name.

Check whether a given last name is the same as the last name of this person.

Check whether a give first name is the same as the first name of this person.

Check whether a given middle name is the same as the middle name of this person.

b) Add the method equals that returns true if two objects contains the same first and last name.

c) Add the method makeCopy that copies the instance of variables of a Person object into another Person object.

d) Add the method getCopy that creates and returns the address of the object, which is a copy of another Person Object.

e) Write the definition of the methods of the class Person to implement the operation of this Class

f) Write a program that tests various operation of the Class Person.

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

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

More Books

Students also viewed these Databases questions

Question

Classify delivery styles by type.

Answered: 1 week ago