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 12:00
Carrie received a w-2 form, 1099-misc, and a 1099-int. what is most likely true about carrie?
Answers: 1
question
Advanced Placement (AP), 23.06.2019 19:30
Briefly explain one difference in the practice of realpolitik by louis napoleon and otto von bismarck.
Answers: 1
question
Advanced Placement (AP), 24.06.2019 05:00
Which courtroom participant is james in the given scenario? josh, the accused, is undergoing a criminal trial. mr. kent, josh’s neighbor and college professor, has been called upon to vouch for josh’s good conduct, academic performance, and likeable behavior. mr. kent is thus playing the role of a in the courtroom.
Answers: 3
question
Advanced Placement (AP), 24.06.2019 07:40
Type the correct answer in each box. use = 3.14 and if necessary, round your answers to the nearest hundredth. the area of the largest cross section of a sphere and the circumference of the sphere are in the ratio 4: 1. cm. the area of the largest cross section is about the radius of the sphere is cm. the circumference of the sphere is about cm2. the volume of the sphere is about cm?
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
Social Studies, 30.11.2020 18:20
question
Mathematics, 30.11.2020 18:20
question
Mathematics, 30.11.2020 18:20
question
Mathematics, 30.11.2020 18:20