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), 21.06.2019 17:30
In a program, highscholl graduates have the chance to learn about and train in a chosen filed in a short period of time
Answers: 1
question
Advanced Placement (AP), 22.06.2019 00:00
According to the article, what are some of the drawbacks of traditional intelligence tests, and what is being done to rectify these issues?
Answers: 3
question
Advanced Placement (AP), 25.06.2019 15:00
Ahypothesis test is conducted with a significance level of 5%. the alternative hypothesis states that more than 65% of a population is right-handed. the p-value for the test is calculated to be 0.03. which of the following statements is correct? we can conclude that more than 3% of the population is right-handed. we cannot conclude that more than 65% of the population is right-handed. we can conclude that more than 65% of the population is right-handed. we can conclude that exactly 3% of the population is right-handed. there is not enough information given to make a conclusion.
Answers: 2
question
Advanced Placement (AP), 25.06.2019 19:30
Symptoms of include nausea, vomiting, improper digestion, and severe abdominal pain, and sufferers may develop diabetes. a. pancreatitis b. hepatitis c. gastritis d. none of the above
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
World Languages, 31.12.2019 11:31
Questions on the website: 13722363