We're going to make a small change to the UserAccount class from the last assignment by adding a new method:

public abstract void getPasswordHelp();

This method is abstract because different types of user accounts may provide different types of help, such as providing a password hint that was entered by the user when the account was created or initiating a process to reset the password. Next we will create a subclass of UserAccount called FacebookUser. The FacebookUser class needs to have the following fields and methods in addition to what is in UserAccount:

Fields:

String passwordHint
ArrayList< FacebookUser> friends

Methods:

void setPasswordHint(String hint)
void friend(FacebookUser newFriend)
void defriend(FacebookUser formerFriend)
ArrayList< FacebookUser> getFriends()

The friend method should add the FacebookUser argument to the friends ArrayList (if that FacebookUser is already in the friends list, display an error message), and the defriend method should remove the FacebookUser argument from that ArrayList (if that FacebookUser is not in the friends list, display an error message). The getFriends method should return a copy of this user's friends - create a new ArrayList with the same FacebookUsers in it as this users friends. Do not return the friends ArrayList directly, since this violates the principle of encapsulation. The getPasswordHelp method should display the passwordHint. The FacebookUser class should also implement the Comparable interface. FacebookUsers should be sorted alphabetically by username, ignoring capitalization. (Hint: notice that the toString method returns the username of the UserAccount.) Finally, write a driver program that creates several FacebookUsers and demonstrates the user of the setPasswordHint, friend, defriend, getFriends, and getPasswordHelp methods. Also, put the FacebookUser objects into an ArrayList, sort them (see the jar file for this topic for help on this), and print them out in sorted order.

You will be graded according to the following rubric (each item is worth one point):

  • The UserAccount class is abstract and has the requested fields and methods
  • The only abstract method is the getPasswordHelp method
  • The FacebookUser class extends UserAccount
  • FacebookUser has a friends ArrayList and methods to add, remove, and display the friends
  • FacebookUser implements Comparable and sorts alphabetically on username, ignoring capitalization
  • FacebookUser has a passwordHint that can be set through a method and is displayed by the getPasswordHelp method
  • The driver program creates a list of FacebookUsers
  • The driver program sorts and displays the lists of FacebookUsers
  • The driver program exercises the setPasswordHint, friend, defriend, getFriends, and getPasswordHelp methods
  • The program compiles and runs and the program is clearly written and follows standard coding conventions
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.