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, 22.06.2019 02:00
Consider how gaming consoles initially relied on joysticks and joypads and then made the switch to modern gaming controls, which include analog sticks, buttons and switches, touch controls, accelerometers, motion controls, etc. name at least two kinds of gaming experiences that are possible with these new control devices but were not possible on original joysticks. explain how new technologies made this newer game style possible.
Answers: 1
question
Computers and Technology, 23.06.2019 01:30
In deadlock avoidance using banker’s algorithm, what would be the consequence(s) of: (i) a process declaring its maximum need as maximum possible for each resource. in other words, if a resource a has 5 instances, then each process declares its maximum need as 5. (ii) a process declaring its minimum needs as maximum needs. for example, a process may need 2-5 instances of resource a. but it declares its maximum need as 2.
Answers: 3
question
Computers and Technology, 23.06.2019 14:30
The basic work area of the computer is it screen that you when you first fire up your computer
Answers: 1
question
Computers and Technology, 23.06.2019 21:40
language consists of basic components, and they are called a. 3; mental images, concepts, and speech b. 2; language acquisition and linguistic relativity c. 3; heuristics, algorithms, and analogies d. 4; phonemes, morphemes, syntax, and semantics e. 2; words and grammar
Answers: 3
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