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
1 month ago
5

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

Computers and Technology
1 answer:
Amiraneli [921]1 month 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
Allan needs to ensure that an object is in a very precise location on a slide. He decides to use the Ruler option to achieve thi
8_murik_8 [892]

Answer:

It can be accessed via the View tab.

Explanation:

The view tab in Microsoft PowerPoint ranks as the 9th tab when counted from the left side. Upon being clicked, it reveals a variety of tools tailored to help visualize slide appearances.

The ruler function is included among these tools and ensures precise placement of objects within slides. This ruler tool can be found in the Show Box, which is the third section from the left following Presentation View and Master View.

8 0
1 month ago
Read 2 more answers
Rewrite following program using for loop no=3456 while no&gt;0 : print(no%10) no=no/10
zubka84 [945]
no=3456 for x in reversed(str(no)): print(x) If you convert the number to a string and reverse it, you will obtain the same outcome.
8 0
20 days ago
Read 2 more answers
7. Which of these statements is true? Agile is a programming language MySQL is a database HTML stands for "Hypertext Markup Link
Harlamova29_29 [932]

Answer:

None of the statements are accurate, although one option appears to lack certain words.

The precise definition is that MySQL functions as a database management system.

Explanation:

Agile is a software development methodology, not a programming language.

HTML denotes "Hypertext Markup Language"

Java and JavaScript are distinct programming languages.

In fact, MySQL serves as a database management system, specifically for managing relational databases, utilizing SQL (Structured Query Language).

5 0
1 month ago
For Adults/Adolescents, you should call/activate EMS: Before providing CPR. After providing CPR for 2 minutes. After an AED has
Natasha_Volkova [897]

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
1 month ago
Compute the approximate acceleration of gravity for an object above the earth's surface, assigning accel gravity with the result
maria [879]

Response:

Written in Python

G = 6.673 *pow(10,-11)

M = 5.98 *pow(10,24)

d = float(input("Enter distance: "))

g = (G * M)/(pow(d,2))

print("Calculated gravity acceleration: "+str(g))

Explanation:

The following line sets the gravitational constant

G = 6.673 *pow(10,-11)

This line establishes the mass of the Earth

M = 5.98 *pow(10,24)

This prompts the user to input the object's distance

d = float(input("Enter distance: "))

This calculates the gravity exerted on the object

g = (G * M)/(pow(d,2))

This line outputs the gravity acceleration without rounding

print("Calculated gravity acceleration: "+str(g))

8 0
1 month ago
Other questions:
  • . Electricians will sometimes call ______ "disconnects" or a "disconnecting means."
    12·1 answer
  • Which of these is an example of the integrity principle that can ensure your data is accurate and untampered with?
    10·2 answers
  • The part of the computer that contains the brain, or central processing unit, is also known as the A.monitor B.modem C.keyboard
    10·1 answer
  • Write a statement that reads a floating point value from standard input into temperature. Assume that temperature. has already b
    6·1 answer
  • A technician with a PC is using multiple applications while connected to the Internet. How is the PC able to keep track of the d
    8·2 answers
  • Consider the following skeletal C program: void fun1(void); /* prototype */ void fun2(void); /* prototype */ void fun3(void); /*
    11·1 answer
  • What are the set of rules to move data from one computer to another?
    11·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
  • The ______ is the information center that drivers need to refer to when they're NOT scanning the road.
    7·1 answer
  • Explain what might happen if two stations are accidentally assigned the same hardware address?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!