Yorkville High School Computer Science Department
Yorkville High School Computer Science Department on Facebook  Yorkville High School Computer Science Department Twitter Feed  Yorkville High School Computer Science Department on Instagram

Yorkville High School Computer Science

ASSIGNMENTS: No Current Assignments

AP Computer Science :: Projects :: Twitter

Rubric
Due: Database Error

Problem

The Java API (application program interface) is a set of classes for building software applications in Java. Many companies provide an API for their programs to allow third-party developers to create programs on top of the company's program. For this project, we are going to use an API to access Twitter.

Part 1: Connecting and Tweeting

For this project we will be using the Twitter4J API. You can go to the website to download or view the JavaDoc.

  1. Unzip this file to start your project.
  2. In BlueJ, go to Tools>Preferences and select the "Library" tab.
  3. Add the lib\twitter4j-core-4.0.2.jar file from the project folder.
  4. After closing BlueJ your project should compile.
  5. Go to Twitter and sign up for an account. You will need to add an email address and mobile phone number. You can delete this account after the project is over if you'd like.
  6. Go to Twitter Apps and choose "Create New App."
  7. Enter whatever you want for the app information and agree to the Developer Agreement.
  8. Edit the .properties file in the project folder to include your project's API keys and token.
  9. In the setUpAndTweet() method, make a tweet using the twitter.updateStatus() method.

Part 2: Most Common Word

You will access the last 2,000 tweets of a person's twitter handle (this can be your own, someone you know, or a public figure) and determine the most common word they use. To do this, you will need to grab a user's most recent 2,000 tweets, store individual words in a data structure of your choice, and then write an algorithm to determine the most common term. Since it would not be interesting to count "the", "a", "and", or similarly all-too common words you need to remove those too-common words. Fortunately, those too-common words are in the file commonWords.txt. Remove those too-common words from the tweeter's list of words before determining the tweeter's most commonly used word. Note: you will need multiple data structures for this assignment – at least one must be an ArrayList.

Once you have all the tweets in a list you need to determine the most common word. You may also want to remove any words starting with the @ symbol since that’s not always interesting. You might find yourself wanting to do things like remove punctuation and sort words.

Sample run:

Please enter a Twitter handle, do not include the @symbol --> realDonaldTrump
Count = 317 out of the last 1978 tweets.
The most common word from @realDonaldTrump is: trump

Please enter a Twitter handle, do not include the @ symbol --> BernieSanders
Count = 179 out of the last 1964 tweets.
The most common word from @BernieSanders is: people

Please enter a Twitter handle, do not include the @ symbol --> NASA
Count = 264 out of the last 1996 tweets.
The most common word from @NASA is: #yearinspace

Please enter a Twitter handle, do not include the @ symbol --> BillNye
Count = 203 out of the last 1579 tweets.
The most common word from @BillNye is: science

Please enter a Twitter handle, do not include the @ symbol --> yhscs
Count = 71 out of the last 406 tweets.
The most common word from @yhscs is: computer
                

Part 3: Investigation

Brainstorm with a partner something interesting to do with Twitter. Use the JavaDocs and sample code as a resource. Here are some ideas:

Yorkville High School Computer Science Department on Facebook Yorkville High School Computer Science Department Twitter Feed Yorkville High School Computer Science Department on Instagram