1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Katena32 [7]
3 years ago
13

This question involves the creation of user names for an online system. A user name is created based on a user’s first and last

names. A new user name cannot be a duplicate of a user name already assigned. You will write the constructor and one method of the UserName class. A partial declaration of the UserName class is shown below.
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 concatenating 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.

The following example shows the contents of possibleNames after a UserName object has been instantiated.

Example

UserName person = new UserName("john", "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"

Write the UserName constructor below.

/** 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)

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.

A helper method, isUsed, has been provided. The isUsed method searches for name in arr. The method returns true if an exact match is found and returns false otherwise.

Assume that the constructor works as specified, regardless of what you wrote in part (a). You must use isUsed appropriately to receive full credit.

Complete the setAvailableUserNames method below.

/** Removes strings from possibleNames that are found in usedNames as described in part (b).

*/

public void setAvailableUserNames(String[] usedNames)
Computers and Technology
1 answer:
Evgen [1.6K]3 years ago
8 0

Answer:

See explaination

Explanation:

import java.util.*;

class UserName{

ArrayList<String> possibleNames;

UserName(String firstName, String lastName){

if(this.isValidName(firstName) && this.isValidName(lastName)){

possibleNames = new ArrayList<String>();

for(int i=1;i<firstName.length()+1;i++){

possibleNames.add(lastName+firstName.substring(0,i));

}

}else{

System.out.println("firstName and lastName must contain letters only.");

}

}

public boolean isUsed(String name, String[] arr){

for(int i=0;i<arr.length;i++){

if(name.equals(arr[i]))

return true;

}

return false;

}

public void setAvailableUserNames(String[] usedNames){

String[] names = new String[this.possibleNames.size()];

names = this.possibleNames.toArray(names);

for(int i=0;i<usedNames.length;i++){

if(isUsed(usedNames[i],names)){

int index = this.possibleNames.indexOf(usedNames[i]);

this.possibleNames.remove(index);

names = new String[this.possibleNames.size()];

names = this.possibleNames.toArray(names);

}

}

}

public boolean isValidName(String str){

if(str.length()==0) return false;

for(int i=0;i<str.length();i++){

if(str.charAt(i)<'a'||str.charAt(i)>'z' && (str.charAt(i)<'A' || str.charAt(i)>'Z'))

return false;

}

return true;

}

public static void main(String[] args) {

UserName person1 = new UserName("john","smith");

System.out.println(person1.possibleNames);

String[] used = {"harta","hartm","harty"};

UserName person2 = new UserName("mary","hart");

System.out.println("possibleNames before removing: "+person2.possibleNames);

person2.setAvailableUserNames(used);

System.out.println("possibleNames after removing: "+person2.possibleNames);

}

}

You might be interested in
Marginal ________ shows how much money can be made if a producer sells one additional unit of a good.
prohojiy [21]
Marginal revenue shows how much money can be made if a producer sells one more additional unit of a good. Marginal revenue is calculated by dividing the change in total revenue by change in total output quantity. Marginal revenue obeys the law of diminishing returns and decreases overtime.
5 0
3 years ago
Read 2 more answers
Classify the following as cross-section or time-series data: Gross sales of 200 ice cream parlors in July 2009
faust18 [17]

Answer:

let us start by stating the definitions of Time series data and Cross sectional data. TIME SERIES DATA: The data which is collected chronologically over time is known as time series data.

Explanation:

Btw brainliest me plss

6 0
2 years ago
What are the features of a strong résumé? Check all that apply.
solniwko [45]

Answer:

A strong resume must be short and complete.

Explanation:

<em>Focus on your work experience. This is what really makes the employers read your resume longer. They would take a look at how long did you worked for a company and the nature of work you have handled to see the relation to the current opening / hiring position that they have. As much as possible, arrange your working experiences from latest to the oldest.  </em>

<em> Instead of enumerating your skills, list down your accomplishments that you have achieved. This would help your potential employers to look at your strengths. </em>

<em> Be honest. As long as you have put in skills and work experiences which you have truly acquired, then you won't have to worry. Mostly, employers, would ask you things that you have put in to your resume. They would ask more information about it then you could just answer it from the heart.</em>

7 0
2 years ago
Dimensional arrays can be created using loops. 2 dimensional arrays can be created using:
Hunter-Best [27]

Answer:

b-Nested Loops

Explanation:

To create a 1-D array we use single loop.For example:-

int a[10];

for(int i=0;i<10;i++)

{

    cin>>a[i];

}

Taking input of a 1-D array.

For creating a 2-D array we use nested loops.

int a[row][column];

for(int i=0;i<row;i++)

{

    for(int j=0;j<column;j++)

    {

          cin>>a[i][j];

    }

}

Hence the answer for this question is nested loops.

7 0
2 years ago
Trina Hauger works for Johnson Electric as a corporate lawyer, and part of her duties are to ensure the ethical and legal use of
Roman55 [17]

Answer:

b) chief privacy officer (CPO)

Explanation:

The CPO is responsible for ensuring the ethical and legal use of information within a company.

Chief knowledge officer (CKO) is a the person responsible for overseeing knowledge management within an organisation. This role is just like the role of chief learning officer.

A chief information officer (CIO) is the person responsible for the management, implementation, and usability of information and computer technologies. The role is also known as chief digital information officer (CIDO)

A chief technology officer (CTO) is the person in charge of an organization's technological demand. This role is also known as a chief technical officer.

From the above explanation; it is clear that the answer is Trina Hauger is a CPO.

5 0
2 years ago
Other questions:
  • Which is a benefit of peer-to-peer networking?
    10·1 answer
  • It is always better to run over and give more information when you are giving a presentation versus quitting on time.
    11·2 answers
  • Write a recursive, bool-valued function, containsVowel, that accepts a string and returns true if the string contains a vowel. A
    5·1 answer
  • Why computer is known as data processing system?
    14·1 answer
  • When you call a ____________ method, it executes statements it contains and then returns a value back to the program statement t
    6·2 answers
  • If someone wanted to talk to a financial institution representative in person they would need to _____.
    5·1 answer
  • What sorts of changes have you been observing in your society in your society in comparison in last 3 years​
    13·1 answer
  • Which types of file formats are the best choice for files that may need to be edited later?
    14·1 answer
  • HELP PLEASE !!!!!!!!!!!! Amy needs to ensure that she can enter a parameter that will match the values End, deadend, and flatend
    8·1 answer
  • you want to be able to restrict values allowed in a cell and need to create a drop-down list of values from which users can choo
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!