answer.
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
Likurg_2
3 months ago
5

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

Computers and Technology
1 answer:
Amiraneli [1K]3 months ago
7 0

The Java code is structured as follows for the specified task

Explanation:

import java.util.*;

class UserName{

  ArrayList<String> potentialNames;

  UserName(String first, String last){

      if(this.isValid(first) && this.isValid(last)){

          potentialNames = new ArrayList<String>();

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

              potentialNames.add(last+first.substring(0,i));

          }

      }else{

          System.out.println("first and last names must only contain letters.");

      }

  }

  public boolean isTaken(String name, String[] namesArray){

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

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

              return true;

      }

      return false;

  }

  public void setValidUserNames(String[] takenNames){

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

      names = this.potentialNames.toArray(names);

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

          if(isTaken(takenNames[i],names)){

              int idx = this.potentialNames.indexOf(takenNames[i]);

              this.potentialNames.remove(idx);

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

              names = this.potentialNames.toArray(names);

          }

      }

  }

  public boolean isValid(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 user1 = new UserName("john","smith");

      System.out.println(user1.potentialNames);

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

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

      System.out.println("available names before deletion: "+user2.potentialNames);

      user2.setValidUserNames(usedNames);

      System.out.println("available names after deletion: "+user2.potentialNames);

  }

}

You might be interested in
Choose the person responsible for each innovation.
zubka84 [1067]

Response:

John Blankenbaker

Reasoning:

5 0
2 months ago
Question #5<br> How does the computer decide which path to follow in a selection control structure?
Harlamova29_29 [1022]

Answer:

In my opinion, the coding structure's elements assist the software or CPU in interpreting or directing the programming.

Explanation:

6 0
2 months ago
For Adults/Adolescents, you should call/activate EMS: Before providing CPR. After providing CPR for 2 minutes. After an AED has
Natasha_Volkova [1026]

Answer:

Before administering CPR is the correct choice.

Explanation:

CPR stands for cardiopulmonary resuscitation, a procedure where the rescuer provides mouth-to-mouth ventilation and chest compressions. Anyone trained in administering CPR to adults or adolescents is expected to call or activate EMS prior to starting the cardiopulmonary resuscitation.

6 0
2 months ago
Assume that a function named swapdoubles has been defined and is available for use in this exercise: that function receives two
Natasha_Volkova [1026]
The provided C++ code is designed to sort three double variables: void sort3(double &a, double &b, double &c). The logic within functions attempts to ensure that these values are ordered correctly, implementing swaps accordingly.
6 0
2 months ago
Other questions:
  • Sarah works in a coffee house where she is responsible for keying in customer orders. A customer orders snacks and coffee, but l
    13·2 answers
  • Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename
    6·2 answers
  • A company requires an Ethernet connection from the north end of its office building to the south end. The distance between conne
    8·1 answer
  • One form of Intrusion Detection System (IDS) starts operation by generating an alert for every action. Over time, the administra
    5·1 answer
  • 7.7 LAB: Using a while loop countdown Write a program that takes in an integer in the range 10 to 100 as input. Your program sho
    11·1 answer
  • Xem tập các tiến trình sau đây, với thời gian cần chạy ở cột Burst Time được cho ở đơn vị mili giây.
    10·1 answer
  • In 2007, this wireless security algorithm was rendered useless by capturing packets and discovering the passkey in a matter of s
    6·2 answers
  • A router has a valid operating system and a configuration file stored in nvram. the configuration file contains an enable secret
    10·1 answer
  • Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined in a namespace royaltyRates. PLEASE DONT F
    14·1 answer
  • On January 1, 1980, Moises deposited $1850 into a savings account paying 5.6% interest, compounded quarterly. If he hasn't made
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!