SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit. A mathematical sequence is an ordered list of numbers. This question involves a sequence called a hailstone sequence. Ifnis the value of a term in the sequence, then the following rules are used to find the next term, if one exists. If n is 1, the sequence terminates. If n is even, then the next term is n2. If n is odd, then the next term is 3n 1. For this question, assume that when the rules are applied, the sequence will eventually terminate with the termn

Respuesta :

Answer:

Check the explanation

Explanation:

CODE:-

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);

  }

}

Kindly check the attached image below for the code output.

Ver imagen temmydbrain

In this exercise we have to use the knowledge of computational language in JAVA to write the code.

This code can be found in the attached image.

To make it simpler the code is described as:

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);

 }

}

See more about JAVA at brainly.com/question/6490447

Ver imagen lhmarianateixeira