subject

1. Write a class Name that stores a person’s first, middle, and last names and provides the following methods: public Name(String first, String middle, String last)—constructor. The name should be stored in the case given; don’t convert to all upper or lower case.
public String getFirst()—returns the first name
public String getMiddle()—returns the middle name
public String getLast()—returns the last name
public String firstMiddleLast()—returns a string containing the person’s full name in order, e. g., "Mary Jane Smith".
public String lastFirstMiddle()—returns a string containing the person’s full name with the last name first followed by a comma, e. g., "Smith, Mary Jane".
public boolean equals(Name otherName)—returns true if this name is the same as otherName. Comparisons should not be case sensitive. (Hint: There is a String method equalsIgnoreCase that is just like the String method equals except it does not consider case in doing its comparison.)
public String initials()—returns the person’s initials (a 3-character string). The initials should be all in upper case, regardless of what case the name was entered in. (Hint: Instead of using charAt, use the substring method of String to get a string containing only the first letter—then you can upcase this one-letter string. See Figure 3.1 in the text for a description of the substring method.)
public int length()—returns the total number of characters in the full name, not including spaces.
2. Now write a program TestNames. java that prompts for and reads in two names from the user (you’ll need first, middle, and last for each), creates a Name object for each, and uses the methods of the Name class to do the following:
a. For each name, print
first-middle-last version
last-first-middle version
initials
length
b. Tell whether or not the names are the same.
Here is my code. I keep getting a method error with getFullName in the Name. java file. Please help me re-write the code to fix this issue.
//Name. java
public class Name
{
private String firstName, middleName, lastName, fullName;
public Name(String first, String middle, String last)
{
firstName = first;
middleName = middle;
lastName = last;
String fullName = firstName '+' middleName '+' lastName;
}
public String getFirst()
{
return firstName;
}
public String getMiddle()
{
return middleName;
}
public String getLast()
{
return lastName;
}
public String firstMiddleLast()
{
return firstName + ' ' + middleName + ' ' + lastName;
}
public String lastFirstMiddle()
{
return lastName + ", " + firstName + ' ' + middleName;
}
public boolean equals(Name otherName)
{
return fullName. equalsIgnoreCase(otherName. getFullName());
}
public String initials()
{
return firstName. toUpperCase().substring(0,1)
+ middleName. toUpperCase().substring(0,1)
+ lastName. toUpperCase().substring(0,1);
}
public int length()
{
return firstName. length() + middleName. length() + lastName. length();
}
}
//NameTester. java
import java. util. Scanner;
public class NameTester
{
public static void main(String[] args)
{
Scanner input = new Scanner(System. in);
String firstName1 = new String();
String middleName1 = new String();
String lastName1 = new String();
String firstName2 = new String();
String middleName2 = new String();
String lastName2 = new String();
System. out. print("\nPlease enter a first name: ");
firstName1 = input. nextLine();
System. out. print("Please enter a middle name: ");
middleName1 = input. nextLine();
System. out. print("Please enter a last name: ");
lastName1 = input. nextLine();
Name name1 = new Name(firstName1, middleName1, lastName1);
System. out. print("\nPlease enter another first name: ");
firstName2 = input. nextLine();
System. out. print("Please enter another middle name: ");
middleName2 = input. nextLine();
System. out. print("Please enter another last name: ");
lastName2 = input. nextLine();
Name name2 = new Name(firstName2, middleName2, lastName2);
System. out. println();
System. out. println(name1.firstMiddleLast()); System. out. println(name2.firstMiddleLast()); System. out. println(name1.lastFirstMiddle()); System. out. println(name2.lastFirstMiddle()); System. out. println(name1.initials());
System. out. println(name2.initials());
System. out. println(name1.length());
System. out. println(name2.length());
if (name1.equals(name2))
System. out. println("The names are the same.");
else
System. out. println("The names are not the same.");
}
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 21:40
Which is a benefit of getting information from a government website? a. the information will be easy to understand. ob. the information will be the most current. oc. the information can be trusted.
Answers: 1
question
Computers and Technology, 22.06.2019 16:30
What type of file does a cookie place on web site visitors' computers so that web site managers can customize their sites to their visitors' preferences?
Answers: 1
question
Computers and Technology, 22.06.2019 19:30
Avariable definition defines the name of a variable that will be used in a program, as well as
Answers: 3
question
Computers and Technology, 23.06.2019 00:30
Pl i need the answer now ! which one of the following is considered a peripheral? a software b mouse c usb connector d motherboard
Answers: 1
You know the right answer?
1. Write a class Name that stores a person’s first, middle, and last names and provides the followin...
Questions
Questions on the website: 13722363