Question
package driverPackage; import java.util.Scanner; import NameClass.Name; //import namePackage.Name; public class ProjectNameClass { private static Scanner keyboard = null; /** * @param args */ public static
package driverPackage;
import java.util.Scanner;
import NameClass.Name;
//import namePackage.Name;
public class ProjectNameClass
{
private static Scanner keyboard = null;
/**
* @param args
*/
public static void main(String[] args)
{
keyboard = new Scanner(System.in);
Name newName = new Name();
// class read methods
System.out.println("Please enter a complete name in the following format. Firstname Middlename Lastname");
getName(newName);
Name myName = new Name(newName.getFirstName(), newName.getMiddleName(), newName.getLastName());
System.out.println("You entered: ");
printNameOut(myName);
Name cloneName = new Name(myName.getFirstName(), myName.getMiddleName(), myName.getLastName());
if (myName.equals(cloneName))
{
System.out.println("You just cloned yourself and your clone now has your name.");
System.out.println("Your name: " + myName.getFullName());
System.out.println("Your clone's name: " + cloneName.toString());
System.out.println(
"You might want to differentiate yourself from your clone" + "by using all uppercase for their name. ");
cloneName.ToUpperCase();
if (myName.equals(cloneName))
{
System.out.println("That did not work they are still equal!");
} else
{
System.out.println("Your name: " + myName.getFullName());
System.out.println("Your clone's name: " + cloneName.toString());
System.out.println("That is better! Now I can tell you appart.");
}
} else
{
System.out.println("You failed to clone yourself!");
}
System.out.println("Please enter another complete name in the following format.");
System.out.println("Firstname Middlename Lastname");
System.out.println("This name should be of the opposite gender");
getName(newName);
Name spouseName = new Name(newName.getFirstName(), newName.getMiddleName(), newName.getLastName());
System.out.print("You entered: ");
printNameOut(spouseName);
myName.mergeNames(spouseName);
System.out.println("After a marriage in some conuntries your names would be:");
System.out.println(myName.toString());
System.out.println(spouseName.getFullName());
System.out.println("You should now enter a new name for yourself and I will change your name.");
System.out.println("Please use the same format as before - Firstname Middlename Lastname seperated by spaces.");
getName(newName);
System.out.print("You entered: ");
printNameOut(newName);
System.out.println("I will now change your name from: " + myName.getFullName() + " to " + newName.toString());
myName.changeNameTo(newName);
if (myName.equals(newName))
{
System.out.print("Your name is now: ");
printNameOut(myName);
}
}
private static void getName(Name newName)
{
// Scanner keyboard = new Scanner(System.in);
newName.setFirstName(keyboard.next());
newName.setMiddleName(keyboard.next());
newName.setLastName(keyboard.next());
keyboard.nextLine();
// keyboard.close();
}
static void printNameOut(Name printName)
{
System.out.println(printName.getFirstName() + " " + printName.getMiddleName() + " " + printName.getLastName());
}
}
Output:
Please enter a complete name in the following format.
Firstname Middlename Lastname
Tommy Lee Jones
You entered:
Tommy Lee Jones
You just cloned yourself and your clone now has your name.
Your name: Tommy Lee Jones
Your clone's name: Tommy Lee Jones
You might want to differentiate yourself from your cloneby using all uppercase for their name.
Your name: Tommy Lee Jones
Your clone's name: TOMMY LEE JONES
That is better! Now I can tell you appart.
Please enter another complete name in the following format.
Firstname Middlename Lastname
This name should be of the opposite gender
Sally May King
You entered: Sally May King
After a marriage in some conuntries your names would be:
Tommy Lee King-Jones
Sally May King-Jones
You should now enter a new name for yourself and I will change your name.
Please use the same format as before - Firstname Middlename Lastname seperated by spaces.
My New Name
You entered: My New Name
I will now change your name from: Tommy Lee King-Jones to My New Name
Your name is now: My New Name
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started