subject

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 Computers and Technology

question
Computers and Technology, 21.06.2019 17:00
Ineed a good science fair name i’m doing a homemade water filter and i have no idea what the title should be plz
Answers: 1
question
Computers and Technology, 22.06.2019 03:40
Hello my name is mihai and i need your : )i have to do a python project in computer science and i’m really busy with my mocks this period of time besides this i’m not good at coding so could someone pls pls pls sort me out ? i actually beg ; ))
Answers: 1
question
Computers and Technology, 22.06.2019 18:00
Determine whether the following careers would require training or college.
Answers: 1
question
Computers and Technology, 23.06.2019 01:00
Let r be a robotic arm with a fixed base and seven links. the last joint of r is a prismatic joint, the other ones are revolute joints. give a set of parameters that determines a placement of r. what is the dimension of the configuration space resulting from your choice of parameters?
Answers: 3
You know the right answer?
Public class UserName
{
// The list of possible user names, based on a user’s first and...
Questions
question
Mathematics, 19.03.2020 09:35
Questions on the website: 13722360