i can't figure out how to answer these in java
1. 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. 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 private ArrayList
possibleNames; /** Constructs a User Name 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 */) Unit 7 Progress Check: FRQ usedNames as described in part (b). Removes strings from possible Names that are found in publie void setAvailableUserNames (String[] usedNames) Il to be implemented in part (b) */ } (a) write the constructor for the User Name 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 first Name 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 User Name object as described in part (a). Precondition: firstName and last Name have length greater than o and contain only uppercase and lowercase letters. public UserName (String firstName, String lastName) Please respond on separate paper, following directions from your teacher. (b) Write the UserName method setAvailableUserNames. The method removes from AP AP Computer Science A Unit 7 Progress Check: FRQ possibleNames all names that are found in used Names. 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. The example below shows the intended behavior of the setAvailableUserNames method. Statement Strings in possibleNames after statement execution String[] used = {"harta". "hartm", "harty"): User Name person2 = new UserName('mary". "hart'); "hartm". "hartma "hartmar". "hartmary" "hartma", "hartmar", "hartmary" person2.setAvailableUserNames(used): 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 possible Names that are found in usedNames as described in part (b). public void setAvailableUser Names (String I usedNames) Please respond on separate paper, following directions from your teacher