The goal of this assignment is to understand the concept of Linked Lists. You will write code that (1) uses the functionality of given LinkedList code, and (2) implements functionality inside the LinkedList class.
We will use LinkedLists to store and process user data from social networking applications. To emphasize problem solving, you will also be required to determine by yourself what helper methods to add inside certain classes to implement the required methods for a given class.
The application involves a social networking site similar to say, LinkedIn. Each user has an account. A user may have zero or more connections. We will maintain the connections of each user as a separate Linked List. In this application, a connection is symmetric; if user X becomes connected to user Y, then Y is also connected to X. It should be possible to find the users that are connected directly to a user or via a common connection. Note that a connection is not reflexive: X can never be considered to be directly or indirectly connected to X.
This application needs three classes:
Implement the Account class as follows:
List of attributes in Account:
Account Constructor:
List of Methods in Account:
However, if X is connected to Y and Z, and Y is connected to Z, we will not count the connection from X to Z as a second-level connection.
Moreover, we only count unique accounts. That is, if A is connected to B and C, and B and C are both connected to D, then you should count the second-level connection between A and D only once.
Finally, remember that A cannot be connected to itself directly or indirectly.
You may find it helpful to include helper methods in the LinkedList class in order to implement the above methods in the Account class. However, that is entirely your choice. We will only test the methods in the Account class. Hint: Look up what methods are available in the ArrayList class (e.g., contains, indexOf, etc) that are not available in the given LinkedList class, and determine which one(s) will make it easier to implement Account.
As always, remember that we will not test your main method. The methods you implement will be tested directly by the test server. Ideally, you should create your own main methods, perhaps one in each class, to test each class separately and together. Preliminary testing will cover some methods and a limited set of situations in these methods. Final testing may use other data.
Here is a sample barebones main method for the Account class. It does not test all the methods, nor does it test for various situations.
public static void main(String[] args){ Account alice = new Account("alice", "Alice A"); Account bob = new Account("bob", "Bob B"); Account cody = new Account("cody", "Cody C"); Account david = new Account("david", "David D"); alice.addConnection(bob); bob.addConnection(cody); cody.addConnection(david); cody.addConnection(alice); System.out.println(alice); System.out.println(alice.getUserName()); System.out.println(alice.getName()); System.out.println(alice.getDirectConnections()); System.out.println(alice.getCommonConnections(cody)); }
Create a single jar file called P6.jar from the two Java files (Account.java and LinkedList.java) using the instructions provided here. Do not add other files (e.g., class files). You should not add Node.java because it is supposed to remain unchanged.
Submit the P6.jar file via the online checkin system.