!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> CS 112: Introduction to Computer Science II

Design and development of significantly sized software using top-down design and bottom-up implementation. Dynamically allocated data, object-oriented programming, architecture of memory, basics of language translation, and basics of algorithm analysis. Development of simple graphical user interfaces. Prerequisite: CS 110 (grade of C or better).

Project 5 - Search Twitter Results using Binary Search Trees - (100 points)



Part 1 - Due date: 5/6/2016 at 11:59pm

Part 2 - Due date: 5/12/2016 at 11:59pm

Objectives



  • Implement your own Binary Search Tree
  • Connect with the Twitter API
  • Gain experience with using an external library: twitter4j
Create a Java Project called project5.

Part 1 : Implement a Binary Search Tree (45 points)



  • Create a class called Node that contains two String attributes named key and value and a left and right attribute that references the left and right node item in the binary search tree. Create a constructor and getters/setters/toString methods for this class.
  • Create a BinarySearchTree class that contains a root and current data attribute of type Node. The constructor for this class should assign root and current to null. For this class, create the following methods:
    • void insert(Node newNode) - This method inserts a node into the binary search tree such that the properties of the binary search tree is maintained at all times.
    • void printTree() - This method prints the contents of the tree. Hint: Use inorder traversal.
    • void search(String searchString) - This method takes a user-specified string (username) and searches for it in the binary search tree. The method prints the value (which in our case would be the tweet) for the user.
  • Create a class called BSTTester that is the driver for testing the methods in the BinarySearchTree class.

Part 2 : Connect with the Twitter API using twitter4j (45 points)



  • Download the twitter4j library to connect to the Twitter API. Note: Download the stable 4.0.4 version
  • Import all the jar files in the lib directory into your project as external jar files
  • Sign up for an account on twitter.com
  • Navigate to the developer site for Twitter. Sign in with your twitter account information.
  • Create a new app and give it a unique name. When creating the app, provide http://www.cs.usfca.edu as the URL. You do not need a callback URL.
  • Once the app is created, click on the "Keys and Access Tokens" tab.
  • Scroll down and click on "Create my access token"
  • Now copy the following four values into a text file and save it on your computer. We will need this later.
    1. Consumer Key (API Key)
    2. Consumer Secret (API Secret)
    3. Access Token
    4. Access Token Secret
  • Now go to the examples directory in your twitter4j download.
  • Start with the SearchTweets.java file. Add the following lines and delete the line Twitter twitter = new TwitterFactory().getInstance();
  • ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true) 
    .setOAuthConsumerKey("yourkey")
    .setOAuthConsumerSecret("yoursecret")
    .setOAuthAccessToken("youraccesstoken")
    .setOAuthAccessTokenSecret("youraccesstokensecret");
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();
    

  • Test that the program works with various search keys and prints a sample of tweets with the search query.
  • Modify this program such that it works with your binary search tree.
  • For every tweet that you find, you will create a new node with the twitter user's screenName as the key and their tweet as the value into the binary search tree.
  • You will then display a sorted list of all the screenNames
  • Ask the user of your program for the search key. Use the binary search tree to look for that key (screenName) and if found, display the corresponding tweet to the user.

Code quality (10 points)



Any necessary deductions that pertain to the quality of code or lack of comments. For example, Lack of access level modifiers for variables or functions, (private, public, protected), Left over commented out code, Left over debug print statements (this affects the performance of your programs), and so on.

Submitting the assignment



  • Right-click on the project name (project5) and after choosing Team->Share Project, choose Team->Commit to commit the files. Select README and your program files (all Java files). Click OK to submit your assignment.
  • If you are attempting the extra credit, please make sure to mention that in the README file.
  • You can resubmit the assignment as many times as you want. It will upload a new copy of the files to the SVN repository. We will only grade the one that is closest to 11:59pm on the due date.