Do the following questions from Schneider & Gersting Third Edition:
In this assignment, you will implement some of the features found in such social networking websites as MySpace and Facebook.
This assignment requires you to think a bit more "algorithmically" than previous ones, so take time to consider your solution before you begin coding.
First, create a class called Person. This should have two attributes: a String called "name" (representing the person's name) and a String array called "friends", representing the names of the person's online friends. You should have accessor methods for both attributes, and also have a constructor that initializes them, too.
Next, create a class called FriendTracker. This class should have one attribute called "people", which is an array of Person objects. It should also have a method called "findPerson", which takes a String as its parameter and returns the Person object (from the "people" array) whose "name" attribute matches the parameter, and returns null if there is no such Person.
The FriendTracker class should also have a method called "loadFile" which takes a String as its parameter, representing the name of the file to read. Each line of the file will start with a person's name, followed by a semicolon, and then a comma-separated list of friends' names, ending with a period, like this:
Charlie: Snoopy, Linus, Lucy.
The loadFile method should read the file one line at a time, and then create a Person object (where the first name represents the "name" attribute, and the rest are the Strings in the "friends" attribute array). It should then add that Person to the "people" array in the FriendTracker class. For simplicity, you can assume that each person has no more than 10 friends, and that there are no more than 100 people in the file. An example file is here. Your program can assume that the file is correctly formatted, and that names will not contain spaces. Be sure to take into account that the String returned by the Scanner's "next" method will also include the punctuation, so you need to remove it before populating the fields in the Person object.
Note: the "findPerson" and "loadFile" methods are crucial to the functionality of the rest of the program so be sure that you get them right! Ask a member of the teaching staff if you need help!
Then, implement the following methods in the FriendTracker class:
Last, create a class called FriendProgram that has a "main" method which creates a FriendTracker object, calls its loadFile method (with the name of the file containing the lists of friends), and then calls the mostFriends, friendsInCommon, and suggestFriend methods to demonstrate that they work correctly.
Hint: all of this functionality can be implemented using arrays, but you may want to look into the ArrayList and HashMap classes from the Java API. You do not have to use those classes, of course, but you are allowed to. You could use an ArrayList instead of a String array in the Person class to represent the names of the person's friends. And you could use a HashMap instead of an array of Person objects in the FriendTracker class to represent the "people" attribute.
Your submission must also include a README file, in which you explain how your program works and how to use it. You need to discuss the algorithms you used to implement the findPerson, mostFriends, friendsInCommon, and suggestFriend methods.
The Theory assignment will be worth a total of 15 points. Each question is worth five points.
The Programming assignment will be worth a total of 85 points, distributed as follows:
|Submitting your assignment|
For the Theory assignment, print a paper copy and submit it at the beginning of class. You do not need to submit it electronically.
For the Programming assignment, submit a paper copy of all your source code and submit it electronically by the due date. Put all your .java files and your README file in a .zip or .tar file, then follow these instructions: