Java Hw5

profilefoooq55
Lab5.pdf

Lab 5

Implementing a System Design with Inheritance (50 points + 5 extra credit)

This lab focuses on the inheritance concepts that we talked about in class. The purpose of the lab is to

practice coding these concepts in Java.

You will be given the system description, requirements and the system design that is based on them. Your

task is to implement (write code for) the design.

System Description:

Recommender systems have emerged in the past decade, and they are found in almost every vital online

service. The role of such systems is to recommend new items to the users. For example, a recommender

system would recommend new videos for a user to watch on YouTube.com, or new products for a

customer to buy on Amazon.com, or new friends for a user on Facebook.com, or new movies for a viewer

on NetFlix.

There are many different recommendation techniques that computer scientists have developed over the

past decade. One of the most popular and widely used techniques is called the User-based Collaborative

Filtering Recommendation Technique, or User-CF for short. The idea behind User-CF is very simple. In

order find out what items would be of interest to a certain user, name him John, User-CF looks for other

users who are similar to John. That is, users that previously liked the same items as John. Then it checks

what other items did these users like, and recommend these items to John. To better understand how

this works, let us study the example shown in the table below.

In the table above, every column represents an animated movie, and every row represents a user. When

a cell contains 1, this indicates that the corresponding user has watched the corresponding movie. For

example, Kelly watched “Alice in Wonderland” and “Meet the Robinsons”.

Now, let us assume that we would like to recommend a movie for John. The first step is to find who the

most similar users to John are. That is, who the users that watched the same movies as John are. We will

find that Adam watched 3 out of the 4 movies that John watched, Madison watched 2 out of 4, and Kelly

watched only 1 out of 4. So, Adam is the most similar user to John. Now, we need to check, what are the

movies that Adam watched but John didn’t? That would be “Alice in Wonderland”. So, we take that movie

and recommend it to John. This is just a very simplified explanation for how User-CF works.

Alice in Wonderland

Meet the Robinsons

Monsters University

Horton Hears a Who

Tangled Lion King

John 1 1 1 1

Kelly 1 1

Adam 1 1 1 1

Madison 1 1 1

System Requirements:

In order for such a recommender system to work, it should keep track of all the movies that each user has

watched. Or, more generally speaking, it should keep track of all the items that the user provided feedback

for. It should also be able to compute the number of items that two users have in common. Each user

should be referenced using a unique ID, and the same applies to each item. The system should also store

the user’s name, the item’s name and description. For the time being, the system will be used to

recommend movies. However, the system design should allow for representing diverse varieties of items

such as movies, books, electronic devices, and any type of commercial product. For movies, the system

should keep the movie’s genre and director.

System Design:

1. The system design will include a class named User to represent a user. That class should include

the user’s ID, name, number of watched items, and a list containing the IDs of the watched items.

The class should include a method for computing the number of similar items between two users.

2. To allow for representing diverse items, the system will include an abstract class named Item to

represent a generic item. This class will include the item’s ID, name and description.

3. To represent movie items, the system will include a class named Movie that inherits from the

abstract Item class. It will include the movie’s genre and director.

UML Diagram for the System Design:

Recall the meanings of the UML Symbols:

- Private

+ Public

# Protected

Lab Work:

1. Implement the system design that is shown in the UML diagram above. Compile your code, and

make sure that it does not return any errors.

2. Don’t forget to implement a constructor for each class, to initialize its data. Let your constructor

print a message indicating successful initialization of the object data.

3. Don’t forget to define the Item class as abstract.

4. In your main method, create three movie objects, and set up their ID’s, names, descriptions and

genres.

5. In the User class, you need to think about the similarity() function, and how to find out the number

of similar items between two users. In that function, you will need to call the get_items() function

to access the items array of the other user.

6. In your main method also, create two user objects and set up their ID’s and names. Let the first

user watch two movies, and the second user watch one movie by adding the corresponding item

ID’s to the users’ list of movies.

7. Run your main function.

8. Extra Credit: Can you create a static variable in the User class that keeps track of the number of

user objects that were created so far, and use it to automatically set up the user ID for each new

user object?

Lab Deliverables:

1. Zip all your code, along with a screen shot showing the output obtained after you compiled and

run your code.