Advanced Placement (AP)
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"

answer
Answers: 1

Other questions on the subject: Advanced Placement (AP)

image
Advanced Placement (AP), 23.06.2019 03:30, schoolwannapass
Read the statements and determine the correct answer for each blank. microorganisms that cause diseases are known as . they thrive best between the temperatures of °f °f. because are usually around 70°f, it the growth of spoilage-causing bacteria. a)
Answers: 2
image
Advanced Placement (AP), 23.06.2019 12:30, alexis0430
Write in detail! for free points + brainliest! you have a green light and are turning right at an intersection, but there is a pedestrian in the crosswalk. explain how you should handle this situation.
Answers: 2
image
Advanced Placement (AP), 25.06.2019 00:00, laurentsupreme
Which of the following statements is true about taste bud preferences? a. taste buds respond exclusively to a certain taste sensation, like saltiness. b. taste buds have the ability to respond to all of the taste sensations. c. taste buds do not differentiate between bitter and salty sensations. d. taste buds have the capability to detect three taste sensations.
Answers: 1
image
Advanced Placement (AP), 25.06.2019 02:30, stacysadousky
If pressure and temperature remain constant, will the volume of gas in the respirometers increase or decrease?
Answers: 1
Do you know the correct answer?
Public class UserName
{
// The list of possible user names, based on a user’s first and...

Questions in other subjects:

Konu
Mathematics, 12.01.2022 14:00