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), 25.06.2019 04:00
You must all emergency vehicles using a siren or flashing lights. a. honk to make your position known to b. follow c. yield the right-of-way to d. drive around
Answers: 1
question
Advanced Placement (AP), 26.06.2019 08:00
If the human population continues to grow, what is a likely effect on land use? a. more land will be used for cities. b. more land will be used for forests. c. more land will be used for grasslands. d. more land will be used for wetlands.
Answers: 2
question
Advanced Placement (AP), 26.06.2019 08:00
The following table lists the birth rate, death rate, and net migration rate for egypt over the past 20 years. on a coordinate plane, plot the birth rate data and death rate data for egypt. clearly, show each data point and label each curve. be sure to label the graph and axes. save a copy of your graph. then answer the following questions: (14 points) a. what was the annual growth rate for egypt in 1990? what is the estimated annual growth rate in 2010? be sure to show your work for each answer. b. where does egypt most likely fall on the demographic transition model? explain your answer using data from the table. describe two changes within egyptian society that would likely be necessary for egypt to transition to the next stage in the model. c. assuming egypt’s current birth rate, death rate, and net migration rate trends continue, what will the country’s annual growth rate likely be in 2030? if this growth rate is accurate, what would its doubling time be in 2030?
Answers: 2
question
Advanced Placement (AP), 27.06.2019 16:50
Ineed somebody to solve the multiple choice questions for the california real estate exam ?
Answers: 2
You know the right answer?
Public class UserName
{
// The list of possible user names, based on a user’s first and...
Questions
question
Biology, 07.12.2020 23:40
question
Computers and Technology, 07.12.2020 23:40
question
Mathematics, 07.12.2020 23:40
Questions on the website: 13722363