Write a second Person class that will have an instance variable of type Name ins
ID: 3533941 • Letter: W
Question
Write a second Person class that will have an instance variable of type Name instead of a String as in project 2. You will use the Name class that was written in project 1. The methods of the Name class become available to solve the methods of the Person class. Use the same methods of the first Person class for this new Person class.
PersonTester class:
package PersonTester;
import java.util.Scanner;
public class PersonTester
{
/**
* This demo program tests the use of the Person class and the incorporation of
* the Name class in the Person class.
* First a new Person class object is built and the user is asked to enter in their full name.
* The program reads the input stream from within the Person class for age and the Name class for complete name data.
* Next build another Person class object, using data from the first Person class object.
* Do an equals compare to the new Person class object and tell the results to the user.
* If done correctly the two Person objects should be Identical
* To differentiate them change the cloned Person object's full name to CAPS.
* Next ask for the name and age of someone of the opposite gender.
* Use the add() method to change the last name of the new spouse to a hyphenated last name.
* Use the changeName() method to change the last name of the user's named Person object.
* Ask the user to input a new name for themselves and then change their Person objects name to this new name.
* @param args
*/
public static void main(String[] args)
{
int ageDifference = 0;
String newSpouseLastName = "";
Person newPerson = new Person();
//class read methods
System.out.println("Please enter a complete name and age in the following format. Firstname Middlename Lastname age");
getName(newPerson);
newPerson.read();
Person myPerson = new Person(newPerson.getFirstName(), newPerson.getMiddleName(), newPerson.getLastName(), newPerson.getAge());
System.out.println("You entered: ");
printPersonOut(myPerson);
Person clonePerson = new Person(myPerson);
if(myPerson.equals(clonePerson))
{
System.out.println("You just cloned yourself and your clone now has your name.");
System.out.println("Your name:" + myPerson.getFullNameToString());
System.out.println("Your clone's name: " + clonePerson.getFullNameToString());
System.out.println("You might want to differentiate yourself from your clone" +
"by using all uppercase for their name. ");
clonePerson.setFullNameToUpperCase();
if(myPerson.equals(clonePerson))
{
System.out.println("That did not work they are still equal!");
}
else
{
System.out.println("Your name: " + myPerson.getFullNameToString());
System.out.println("Your clone's name: " + clonePerson.getFullNameToString());
System.out.println("That is better! Now I can tell you appart.");
}
}
else
{
System.out.println("You failed to clone yourself!");
}
System.out.println("Now we will make another person.");
System.out.println("This person should be of the opposite gender");
newPerson.read();
Person bridesPerson = new Person(newPerson.getFirstName(), newPerson.getMiddleName(), newPerson.getLastName(), newPerson.getAge());
System.out.print("You entered: ");
printPersonOut(bridesPerson);
newSpouseLastName = bridesPerson.getLastName();
Person newSpouse = myPerson.add(bridesPerson);
myPerson.changeNameTo(myPerson.getFirstName(), myPerson.getMiddleName(), myPerson.getLastName() + "-" + newSpouseLastName);
System.out.println("After a marriage in some conuntries your names would be:");
System.out.println(myPerson.getFullNameToString());
System.out.println(newSpouse.getFullNameToString());
ageDifference = myPerson.getAge() - newSpouse.getAge();
if(ageDifference >= 5)
{
System.out.println("Wow!! What a craddle robber!!");
}
else if( ageDifference <= -5)
{
System.out.println("Wow!! Talk about marying someone older!!");
}
System.out.println("You should now enter a new name for yourself and I will change your name.");
newPerson.readName();
System.out.print("You entered: ");
System.out.print(myPerson.getFullNameToString());
System.out.println("I will now change your name from: " + myPerson.getFullNameToString()+ " to " + newPerson.getFullNameToString());
myPerson.changeNameTo(newPerson);
if(myPerson.equals(newPerson))
{
System.out.print("Your name is now: ");
System.out.print(myPerson.getFullNameToString());
}
System.exit(0);
}
static void printPersonOut(Person printPerson)
{
System.out.println(printPerson.getFirstName() + " " +
printPerson.getMiddleName() + " " +
printPerson.getLastName() + " age: " +
printPerson.getAge());
}
}
Explanation / Answer
I can do this. But the question is not clear to me. contact me on timacs12@gmail.com with your whole assignment
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.