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
mart [117]
4 years ago
5

Assume that the classes listed in the Java Quick Reference have been imported where appropriate.

Computers and Technology
1 answer:
Neko [114]4 years ago
7 0

The following java code will be written for the prescribed

<u>Explanation:</u>

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
Why can’t a computer use source code
Elina [12.6K]

Answer:

A computer can use a source code

Explanation:

The code that was copied

gets compiled by the terminal and

gets its traced erased

therefore there is no need to give

credit and code still used in proccess

Example:

You can get a source code from stackoverflow

github, you can use that code to build your website

giving no credit to the owners of that code

the code will get its traced erased by the compiler

5 0
3 years ago
Read 2 more answers
What is the definition of a performance, such as a poetry reading? O A. A work of art installed in public OB. A presentation of
Anvisha [2.4K]

Answer:

(B) A presentation of creative works.

Explanation:

Because performing is similar to presenting and poetry is similar to free writing, or creative words.

3 0
3 years ago
Is GLaDOS from portal 2 possible?
77julia77 [94]

Answer:

Explanation:Yes Glados 2 is posible.

8 0
4 years ago
Prior to the world wide web as we know it today, the internet was chaotic, without any ____.
atroni [7]
Search engines - there was no single way to ask a question
5 0
4 years ago
Give at least three aftercare Activities you apply in cleaning airpot.<br>a.<br>b.<br>c.​
maria [59]

Answer: See explanation

Explanation:

An airpot is typically used in keeping of drinks warm. They can be used for outdoors or during meetings. Three aftercare activities that one can apply in cleaning airpot include:

a. To clean an airpot, use a damp cloth and soapy water after the remaining fluid that remains in the airpot has been emptied.

Ab. When cleaning an airpot, it should be noted that corrosive chemicals should not be used to clean them due to the fact that they aren't dishwasher safe.

c. Before storing the airpot, one needs to ensure that every part of the airpot gets dry.

5 0
3 years ago
Other questions:
  • Create a class in JobApplicant.java that holds data about a job applicant. Include a name, a phone number, and four Boolean fiel
    13·1 answer
  • What is the difference between a learner’s license and an operator’s license?
    13·1 answer
  • The primary role of the firewall is to: block unauthorized access to and from the system. quarantine any malware until it can be
    11·1 answer
  • If you reset your iPhone will it delete everything including your Apple ID information
    9·2 answers
  • Rebecca completed work on a computer and is verifying the functionality of the system when she finds a new problem. This problem
    14·1 answer
  • Roblox published a series of videos to help their audience use their creation engine, what are they called?
    7·2 answers
  • Maria is comparing her history project's second-place award to her classmate's first-place award. She starts planning how to win
    9·2 answers
  • You want to substitute one word with another throughout your
    13·1 answer
  • The function ________ returns a value or reference of the cell at the intersection of a particular row and column in a given ran
    14·1 answer
  • How do you select from the insertion point to the beginning of the current line?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!