To give you practice with Java hashmaps.
To introduce you to Java’s built-in lists.
To introduce you to Javadoc, Java’s built-in documentation system.
Many websites recommend books and movies based on combinations of items that other people have liked. For example, if Sue likes "Avatar" and "Driving Miss Daisy" and Joe likes "Avatar", the system might recommend that Joe watch "Driving Miss Daisy". This week, we use this problem as a foundation for practicing with hashtables, lists, and Javadoc (Java’s documentation system).
Our goal is to create a recommendation system that contains a mapping from users to lists of items that they like. You might want to think about how you would design this before seeing the detailed problems below.
If you want to use the LinkedList classes, you first need the following statement at the top of your file:
The following code fragment shows how to create a list with two elements:
LinkedList<Integer> newlist = new LinkedList<Integer>();
The Java documentation for lists will help you locate other list operations that you might need for this lab.
These problems work through information that we will assume you know in the rest of the course. Even if you have to work briefly at home to finish these up, please do so as they will affect future lectures or assignment requirements.
Create a Recommender class with a hashmap called Likes that maps names of people to lists of names of items (books, movies, songs, etc). Use Java’s LinkedList class as described above for the list. Use an appropriate access modifier to prevent another class from accessing or editing the hashtable directly.
You may find Java’s hashmap documentation useful for reference.
Add a method addLikes that consumes the name of a person and the name of an item and adds that item to the person’s likes entry.
Add a method bothLiked that consumes the name of a person and the names of two items and returns a boolean indicating whether the person likes both items.
Create an IRecommender interface for the class that requires the addLikes and bothLiked methods.
Now, we want to add documentation to this system. Java has a built-in documentation system called Javadoc that produces documentation in html. Both DrJava and Eclipse have options for generating Javadoc output automatically (in DrJava, go to the Tools menu, then Javadoc; in Eclipse, go to "Generate Javadoc" under the Project menu). Run Javadoc documentation generation on your Recommender class. Explore the output: what has Javadoc detected automatically about your class hierarchy?
Your generated documentation is missing some important details, like descriptions (purpose statements) of the methods. Javadoc has an annotation language, with which you add such details to fields and methods through stylized comments. See this tutorial on Javadoc. Use it to add your name to your file and purpose statements to each method.
Submit all .java files that you produced for this assignment to the Lab5 area via Turnin.