Programming Project 3

In this project, you'll be writing some code to create various classes that model features of social media. For example, a website like Facebook is rich in properties about its users that can be theoretically mined for beneficial purposes, such as predicting depression in someone based on their activity and offering support and help, or less benign, such as targeting advertisements. In particular, after successfully completing this project, you'll have met the following goals:


Once you have completed this project, you will be ready to take Assessment 6. You will be uploading and using your own code for Assessment 6, so make sure to spend time commenting your code and making it clean and easy for you to work with. Assessment 6 will measure your understanding of generics and collections.


Introduction

Most young adults in the United States spend significant amount of time on social media, such as Facebook, Reddit, Youtube, and Twitter. Various studied have used data available on websites like Facebook to identify and help users with depression, for example. Many applications make use of social networks; for example, many networking and dating applications draw data from Facebook profiles to connect users.

Conversationprism In this project, we will attempt to model a basic social network where users have a profile, photos, and the ability to make posts and messages. We'll keep our model very simple for the sake of this project, but we'll explore some aspects of mining information from our social network. We'll assume that this is a research project, and the data from the social media network has been downloaded and saved as a file full of strings; we'll need to recreate the social network before we can then analyze it.

This assignment will ask you to write several classes, which we will detail below. Once you've written one or more classes, you can test them against our test cases. When all of your classes are completed, you can run them against a simulator we've written to show how these various social network elements can be mined for useful information.

You will have to do the following for this assignment:

The diagram below shows the relationship between various classes:

Warning! This project will ask you to implement our social network in a very inefficient manner! You'll witness how we do lots of things that we shouldn't really, given what we know about generics and collections at this point. We'll detail these inefficiencies throughout this specification; in Assessment 6, you'll have a chance to refactor your code for a more efficient and maintainable solution.


Step 1: Write the following classes


class Profile
The purpose of this class is to model a user's profile on our social networking site.
ATTRIBUTES (please do not change their names)
Object[] photos This array will store Photo objects. Warning! It's pretty inefficient to use primitive arrays, which are static in size, to store a growing number of photos. Similarly, by having the type of the array be Object, we will unfortunately and potentially unsafely have to cast back to the Photo type each time we want to access and use a stored photo. These inefficiencies will exist in the three other attributes below as well.
Object[] contacts This array will store String objects which are the names of contacts.
Object[] posts This array will store Post objects.
Object[] messages This array will store Message objects.
String username This will store the username of the person who holds the profile.
String gender This will store the gender of the person who holds the profile.
METHODS (please do not change their names)
public Profile(String username, String gender) This constructor will set the attributes to the incoming arguments.
getters/setters for all the attributes above Use the Source option to automatically generate these in Eclipse.
public void parseDataDump(Object[] lines) This method takes an array of data, and parses the elements as strings to try to build a profile from the data. It will use all four of the methods below to try to match one of those elements; if a line in the incoming argument doesn't match any of those four types, this method will raise a DataParseException (which is a class you will create, described below).
private boolean minePhoto(String line) This method is used by parseDataDump to check if a line is a Photo or not; if it is, the inefficientAndDangerousAddObject will be called below to add a newly created Photo object to this profile (this method is detailed below).

A line is a photo if it contains the string :/, because photos are stored at a location (such as a URL or folder). Such a line will start with this location of the photo, followed by a space, followed by the size of the photo. The name of a photo will be the string occurring after the last / in the filename.
private boolean mineContact(String line) This method is used by parseDataDump to check if a line is a contact or not; if it is, the inefficientAndDangerousAddObject will be called below to add a new contact (a string) to this profile (this method is detailed below).

A line is a contact if it starts with the string CONTACT, followed by a space, followed by the first and last name of another user (separated by another space).
private boolean minePost(String line) This method is used by parseDataDump to check if a line is a Post or not; if it is, the inefficientAndDangerousAddObject will be called below to add a new post to this profile (this method is detailed below).

A line is a post if it starts with the string POST, followed by a #, followed by the date, followed by a #, followed by the text of a post. On this line, a post may be associated with a photo as well, at the end; both the post and the photo should be added to the profile.
private boolean mineMessage(String line) This method is used by parseDataDump to check if a line is a Message or not; if it is, the inefficientAndDangerousAddObject will be called below to add a new post to this profile (this method is detailed below).

A line is a message if it starts with the string MESSAGE, followed by a #, followed by a contact, followed by a #, followed by the date, followed by a #, followed by the text of a post. Both the post and the contact should be added to the profile.
public void inefficientAndDangerousAddObject(Object object) This method uses the instanceof keyword on the incoming object to determine its type, and adds it to the correct array. Warning! This is an inefficient and dangerous way to add objects to their respective arrays. Think about how you'd want to rewrite this for your assessment. Remember that arrays in Java are fixed in size; each time a new item is added to the array, it must grow incrementally by one unit (once again, extremely inefficient, and think about how you could improve this for your assessment).

In this method, make sure not to store duplicate photos.

class Photo
A Stream of Stars over Paranal The purpose of this class is to store basic information about a photograph. Because photographs can be large files, and we don't actually need the contents of them directly, we end up just storing their location and some other metadata. This is a smart way to save space on our computer, rather than storing (multiple) copies of a large file.
ATTRIBUTES (please do not change their names)
int size This will hold the size of a photo.
String name This will hold the name of a photo.
String location This will hold the location of a photo (such as a file or a URL).
METHODS (please do not change their names)
public Photo(String name, int size, String location) Sets the attributes to the incoming arguments.
getters/setters for all attributes Use the Source option to automatically generate these in Eclipse.
public boolean equals(Object o) Override the method to compare the photo locations for equality.

class Post
The purpose of this class is to store basic information about a post made by a user. Posts can also contain a single photo.
ATTRIBUTES (please do not change their names)
String date This will hold the date of the post.
String text This will hold the contents of a post.
Photo photo This will hold a photo that may be included with a post. Warning! What if there is no photo with this post? Is it a good idea to leave this field empty in such a case? What would be a better way to handle this situation?
METHODS (please do not change their names)
public Post(String date, String text) Sets the attributes to the incoming arguemnts.
getters/setters for all attributes Use the Source option to automatically generate these in Eclipse.
public void addPhoto(Photo photo) Behaves the same way as the setter.

class Message
The purpose of this class is to store basic information about a post made by a user. Posts can also contain a single photo.
ATTRIBUTES (please do not change their names)
String contact This will hold the recipient of the message.
String date This will hold the date of a message.
String body This will hold the contents of a message.
public static final String[] NEGATIVE_WORDS These are a set of words with negative connotations that can be used to help determine the mood and other features of the sender of the message. Here are the keywords: "terrible", "strange", "mad", "furious", "aggressive", "aloof", "arrogant", "belligerent", "big-headed", "bitchy", "boastful", "bone-idle", "boring", "bossy", "callous", "cantankerous", "careless", "changeable", "clinging", "compulsive", "conservative", "cowardly", "cruel", "cunning", "cynical", "deceitful", "detached", "dishonest", "dogmatic", "domineering", "finicky", "foolish", "foolhardy", "fussy", "greedy", "grumpy", "gullible", "harsh", "impatient", "impolite", "impulsive", "inconsiderate", "inconsistent", "indecisive", "indiscreet", "inflexible", "interfering", "intolerant", "irresponsible", "jealous", "lazy", "Machiavellian", "materialistic", "mean", "miserly", "moody", "narrow-minded", "nasty", "naughty", "nervous", "obsessive", "obstinate", "overcritical", "overemotional", "parsimonious", "patronizing", "perverse", "pessimistic", "pompous", "possessive", "pusillanimous", "quarrelsome", "quick-tempered", "resentful", "rude", "ruthless", "sarcastic", "secretive", "selfish", "self-centred", "self-indulgent", "silly", "sneaky", "stingy", "stubborn", "stupid", "superficial", "tactless", "timid", "touchy", "thoughtless", "truculent", "unkind", "unpredictable", "unreliable", "untidy", "untrustworthy", "vague", "vain", "vengeful", "vulgar", "weak-willed"
public static final String[] POSITIVE_WORDS These are a set of words with positive connotations that can be used to help determine the mood and other features of the sender of the message. Here are the keywords: "adaptable", "adventurous", "affable", "affectionate", "agreeable", "ambitious", "amiable", "amicable", "amusing", "brave", "bright", "broad-minded", "calm", "careful", "charming", "communicative", "compassionate", "conscientious", "considerate", "convivial", "courageous", "courteous", "creative", "decisive", "determined", "diligent", "diplomatic", "discreet", "dynamic", "easygoing", "emotional", "energetic", "enthusiastic", "exuberant", "fair-minded", "faithful", "fearless", "forceful", "frank", "friendly", "funny", "generous", "gentle", "good", "gregarious", "hard-working", "helpful", "honest", "humorous", "imaginative", "impartial", "independent", "intellectual", "intelligent", "intuitive", "inventive", "kind", "loving", "loyal", "modest", "neat", "nice", "optimistic", "passionate", "patient", "persistent", "pioneering", "philosophical", "placid", "plucky", "polite", "powerful", "practical", "pro-active", "quick-witted", "quiet", "rational", "reliable", "reserved", "resourceful", "romantic", "self-confident", "self-disciplined", "sensible", "sensitive", "shy", "sincere", "sociable", "straightforward", "sympathetic", "thoughtful", "tidy", "tough", "unassuming", "understanding", "versatile", "warmhearted", "willing", "witty"
METHODS (please do not change their names)
public Message(String contact, String date, String body) Sets the attributes to the incoming arguemnts.
getters/setters for all attributes Use the Source option to automatically generate these in Eclipse.
public static ArrayList getNegativeKeywords(String body) Mines the incoming string for all negative keywords.
public static ArrayList getPositiveKeywords(String body) Mines the incoming string for all positive keywords.

class DataParseException
The purpose of this class is to model an Exception during the parsing of social media data. It extends the Exception class.
METHODS (please do not change their names)
public DataParseException(String message) Calls the parent class' constructor with the argument.

class Analyzer
The purpose of this class is to analyze a text file of profiles, to make determinations about the content posted.
ATTRIBUTES (please do not change their names)
Profile[] profiles The class can hold up to 100 profiles.
int count A count of how many profiles have been detected.
METHODS (please do not change their names)
public void parse(String[] fileLines) throws DataParseException This method will go through the lines of a file and add Profile objects to the object. Each new profile starts with the word PROFILE in the data file, followed by a space, followed by the name, followed by a space, followed by the gender of the person. The subsequent lines will all be posts, messages, and photos that belong to that profile, and should be added to the profile object accordingly.
getters/setters for all attributes Use the Source option to automatically generate these in Eclipse.
public List analyzeProfiles() This method will analyze the profiles contained in the object, and flag all those that are negative, returning those usernames. It will collect all negative messages from all profiles in the object.


Step 2: Testing Your Code For Functionality and Elegance

Please log in again to view these unit tests and simulator code.


The unit tests will, in addition to correctness, measure the following elegance metrics:

Coding style and readability Make sure you use descriptive variables names, proper indentation, etc.
Class, attribute, and method documentation Make sure you comment the purpose of each of these items.
Adherence to abstraction barriers
  • Public methods are used to access private class attributes, rather than accessing them directly.
  • The minePhoto method is called in minePost, rather than rewriting this code.
  • The mineContact method is called in mineMessage, rather than rewriting this code.
  • Uses Photo's equals method to compare two photos for equality in inefficientAndDangerousAddObject.
  • The Analyzer class properly delegates to the parseDataDump method without calling the mine methods created elsewhere.
Code elegance
  • equals should be crash-proof.
Inheritance correctness and safety
  • The @Override tag is used in all the appropriate places.
  • All appropriate attributes are private.


Step 3: Running your code as a simulation

Now that you've successfully completed and debugged your code, you can use your classes to try to determine the mood of people making Facebook posts...or in our case, people on Amazon leaving reviews for a vacuum. The final unit test loads a data file of Amazon reviews for a vacuum; you can see if your analyzeProfiles correctly labels the reviews as positive or negative. Part of your grade will be the percent of correct decisions your classifier makes! Although you're welcome to work with your friends on this project, we will be checking that your classifier code is original and not simply copied from other students in the class, in order to prepare you for future courses where the Honor Code may apply to your work.

Feel free to play around with your analyzeProfiles code, for example:


Step 4: Preparing for Assessment 6

Create a copy of all of your files in a separate directory (preferably a new project in Eclipse). Then, modify those files to get them to pass the unit tests of Sample Assessment 6.