subject
Advanced Placement (AP), 20.02.2020 17:45 yialefi

Public class UserName
{
// The list of possible user names, based on a user’s first and last names and initialized by the constructor.

private ArrayList possibleNames;
/** Constructs a UserName object as described in part (a).
* Precondition: firstName and lastName have length greater than 0
* and contain only uppercase and lowercase letters.
*/

public UserName(String firstName, String lastName)
{ /* to be implemented in part (a) */ }

/** Returns true if arr contains name, and false otherwise. */

public boolean isUsed(String name, String[] arr)
{ /* implementation not shown */ }

/** Removes strings from possibleNames that are found in usedNames as described in part (b).*/

public void setAvailableUserNames(String[] usedNames)

{ /* to be implemented in part (b) */ }

}
a. Write the constructor for the UserName class. The constructor initializes and fills possibleNames with possible user names based on the firstName and lastName parameters. The possible user names are obtained by linking lastName with different substrings of firstName. The substrings begin with the first character of firstName and the lengths of the substrings take on all values from 1 to the length of firstName. Example: firstName: "John" lastName: "Smith". After the code segment has been executed, the possibleNames instance variable of person will contain the following String objects in some order. "smithj", "smithjo", "smithjoh", "smithjohn"

b. Write the UserName method setAvailableUserNames. The method removes from possibleNames all names that are found in usedNames. These represent user names that have already been assigned in the online system and are therefore unavailable. The helper method isUsed has been provided and is properly implenented, and must be used. The isUsed method searches for name in arr. The method returns true if an exact match is found and returns false otherwise.
statement: String[] used = {"harta", "hartm", "harty"};
statement: UserName person2 = new UserName("mary", "hart");
possibleNames after statement execution: "hartm", "hartma", "hartmar", "hartmary"
statement: person2.setAvailableUserNames(used) ;
possibleNames after statement execution: "hartma", "hartmar", "hartmary"

ansver
Answers: 1

Another question on Advanced Placement (AP)

question
Advanced Placement (AP), 23.06.2019 00:30
70 ! in 2-3 paragraphs of 250-300 words, compare and contrast parallel and relative keys. give clear definitions and specific examples to support your answer.
Answers: 2
question
Advanced Placement (AP), 24.06.2019 18:30
Ascientist has predicted that the population of earth will continue to grow exponentially until the year 2300. at that point, we will reach carrying capacity of earth’s resources, and population growth will plateau. if the scientist’s prediction is correct, what can you predict about human energy use at that time? justify your answer by explaining the relationship between population growth and energy use. (5 points)
Answers: 1
question
Advanced Placement (AP), 25.06.2019 22:00
When must a driver yield to a pedestrian? a. only when the pedestrian is in the roadway b. only when the pedestrian is in a designated crosswalk c. only when the pedestrian has a walk signal d. always
Answers: 1
question
Advanced Placement (AP), 25.06.2019 23:00
What is the term for a loan with a cosigner? an automobile loan a guaranteed loan a consignment loan a contractual loan
Answers: 1
You know the right answer?
Public class UserName
{
// The list of possible user names, based on a user’s first and...
Questions
question
Biology, 11.10.2019 09:30
Questions on the website: 13722367