Homework 4 Due 11/02

(1)Representing a Tweet (60 pts)

Twitter and other social media has become a valuable source of data to all types of scientest. Not only can earthquakes be tracked, the spread of the flu modeled, or a users sentiment be derived, but it has seen wide adoptation in the social sciences as tool to learn about communities and culture.

For this problem, you are to implement a class named Tweet. There is a mixture of coding exercises and short answer questions. For the coding exercises, be sure to name your methods the same as what is given in the problem or your code may not work when tested.

An example tweet:

Hello #Pluto! We’re at closest approach. Congrats to all! Follow our story & view new images using #PlutoFlyby. pic.twitter.com/8JVlJrcUkY

— NASA New Horizons (@NASANewHorizons) July 14, 2015

(1a) Constructor Writing (10pts)

Write a constructor with the following signature: Tweet(String content, String user, GregorianCalendar datetime, HashMap<String,GregorianCalendar> retweets, HashMap<String,GregorianCalendar> favorites)

Your constructor should make a new Tweet object with appropriate member variables.

(1b) addRetweet (5 pts)

After we have created a Tweet object, an additional user retweets the tweet. Add a method addRetweet(GregorianCalendar time, String user) to the Tweet class.

(1c) addFavorite (5pts)

After we have created a Tweet object, an additional user favorites the tweet. Add a method addFavorite(GregorianCalendar time, String user) to the Tweet class.

(1d) getNumberOfRetweets (5 points)

Write a method named getNumberOfRetweets() that returns how many times this tweet has been retweeted. The return type is up to you, but should be logical.

(1e) getNumberOfFavorites (5 Points)

Write a method named getNumberOfFavorites() that returns how many times this tweet has been favorited. The return type is up to you, but should be logical.

(1f) Find the earliest retweet (10 points)

A HashMap does not maintain order. Finding the earliest retweet therefore is more complex then returning the "first" or "last" item in the map. Write a method named getFirstRetweet() that returns the name of the user that made the first retweet.

(1g) Counting the number of hashtags (10 points)

When dealing with twitter data, it can be helpful to know various statistics about a tweet. One might be the number of hashtags contained in a tweet. Write a function named getNumberOfHashtags() that returns the number of times the character '#' appears in the tweet.

(1h) Thinking about inheritence (10pts)

Suppose our research leads us to investigate other types of social media posts. Assuming we still want to focus on text-based mediums, what type of base class could you create that your Tweet class would then inherit from? Describe in a paragraph what is common between a social media post in general and would therefore be in the base class, and what might need to remain in the Tweet class.

(2) Sorting the Turing Award Winners (40 pts)

Using the same dataset from HW3, complete the following questions. Feel free to use your response from HW3 as a guide, but remember Java is an Object Oriented Language, so your implementation should reflect this. The files TuringDriver.java and TuringWinner.java have been provided to you.

They may also be copied out of my public directory using the following commands:
  cp /afs/umbc.edu/users/b/w/bwilk1/pub/TuringDriver.java .
  cp /afs/umbc.edu/users/b/w/bwilk1/pub/TuringWinner.java .

For this problem, you will be given a text file in the following format :

  1966   Alan Perlis Yale University Compilers
  1967   Maurice Wilkes University of Cambridge Hardware

The file is a tab delimited file with the following fields: year of the award, name, area of award, and institution

You can download it here. or use the following command to get it.

wget http://www.csee.umbc.edu/courses/331/fall15/05/hw/turing.txt

If you are working on GL, wget will not work, so use the following command to directy copy it from my public directory:

cp /afs/umbc.edu/users/b/w/bwilk1/pub/turing.txt .

(2a) Reading the file (10 pts)

Implement a method called readWinners(String filename) in the provided TuringDriver.java that takes a file name as a string and returns an ArrayList of TuringWinner, which is provided for you.

(2b) Implement ReasonCompator (10 pts)

Sort the table alphabetically by the area of research the award was given for. To do this will you need to make a class named ReasonComparator that implements the Comparator interface.

The output should look something like this:

1975    Allen Newell    Carnegie-Mellon University      AI
1971    John McCarthy   MIT     AI
2011    Judea Pearl     UCLA    AI
1969    Marvin Minsky   MIT     AI
1975    Herbert Simon   Carnegie-Mellon University      AI
1994    Raj Reddy       Carnegie-Mellon University      AI
1994    Edward Feigenbaum       Stanford University     AI
1986    John Hopcroft   Cornell University      Algorithms

(2c) Implement InstitutionComparator (10 pts)

Sort the table alphabetically by the institution of the winner. To do this will you need to make a class named InstitutionComparator that implements the Comparator interface.

The output should look something like this:

1983    Kenneth Thompson        Bell Telephone Laboratories     Operating Systems
1968    Richard Hamming Bell Telephone Laboratories     Coding Systems
1983    Dennis Ritchie  Bell Telephone Laboratories     Operating Systems
2004    Robert Kahn     CNRI    Internet
2007    Joseph Sifakis  CNRS    Model Checking
2007    Edmund Clarke   Carnegie Mellon University      Model Checking
1975    Herbert Simon   Carnegie-Mellon University      AI
1975    Allen Newell    Carnegie-Mellon University      AI

(2d) Implement the toString() of TuringWinner (5 pts)

Add to toString method to the class TuringWinner

(2e) Reflection on Lua and Java (5 pts)

You have now implemented a solution to roughly the same problem in both Lua and Java. Write a paragraph or two about what parts of the solution were easier and Lua and what parts were easier in Java. Provide reasons for why something was easier in Lua or Java. A possible solution to the problem in Lua is available here.

How to Run

To compile your code run:
  javac TuringWinner.java InstitutionComparator.java ReasonComparator.java TuringDriver.java
To run your code:
  java TuringDriver

How to Submit

Your homework should be done on the GL systems. For question numbers 1h and 2e, submit a text file named hw4.txt. For the other questions, write your answers in files dictated by the class names.

Submit your homework using the following command:

submit cs331_bwilk1 hw4 hw4.txt TuringWinner.java InstitutionComparator.java ReasonComparator.java TuringDriver.java Tweet.java

Please test out the submission command before the due date. If you have any problems submitting, email me.