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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:10, lberman2005p77lfi
The total cost of textbooks for the term was collected from 36 students. create a histogram for this data. $140 $160 $160 $165 $180 $220 $235 $240 $250 $260 $280 $285 $285 $285 $290 $300 $300 $305 $310 $310 $315 $315 $320 $320 $330 $340 $345 $350 $355 $360 $360 $380 $395 $420 $460 $460
Answers: 2
image
Computers and Technology, 23.06.2019 03:00, tay9122
Jason, samantha, ravi, sheila, and ankit are preparing for an upcoming marathon. each day of the week, they run a certain number of miles and write them into a notebook. at the end of the week, they would like to know the number of miles run each day, the total miles for the week, and average miles run each day. write a program to them analyze their data. your program must contain parallel arrays: an array to store the names of the runners and a two-dimensional array of five rows and seven columns to store the number of miles run by each runner each day. furthermore, your program must contain at least the following functions: a function to read and store the runners’ names and the numbers of miles run each day; a function to find the total miles run by each runner and the average number of miles run each day; and a function to output the results. (you may assume that the input data is stored in a file and each line of data is in the following form: runnername milesday1 milesday2 milesday3 milesday4 milesday5 milesday6 milesday7.)
Answers: 3
image
Computers and Technology, 23.06.2019 06:30, Zieken993
Martha is designing a single-player game. her manager suggests that she plan the design to incorporate future modifications. which principle of game design relates to planning for future modifications?
Answers: 1
image
Computers and Technology, 24.06.2019 03:00, paguy12
What is one potential problem associated with an organization purchasing new technology early in its lifecycle
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 in other subjects:

Konu
Mathematics, 18.12.2020 23:30
Konu
Mathematics, 18.12.2020 23:30
Konu
Mathematics, 18.12.2020 23:30