SlideShare a Scribd company logo
Lab 8
User-CF Recommender System – Part I
50 points
In this lab, we will focus on understanding the design of a user-
based collaborative filtering
recommender system. Then we will implement half that design
in this lab, and the other half in
the next lab.
System Description:
A user-based collaborative filtering (User-CF for short)
recommender works by making use of the
similarities between users in a system. To recommend items for
a specific user u, first User-CF finds the
n-most similar users to u. These are called the neighbors of u.
Then, the items that ratings that were given
by the neighbors of u for the different items are used to
generate recommendation scores for each item.
Finally, the m items with the highest recommendation scores are
recommended to u. The number of
neighbors n, and the number of items m can vary based on the
application in which the recommender is
used.
The overall flow of the user-based collaborative filtering
recommendation process can be summarized in
these steps:
1. Read movie information from file
2. Read user information from file
3. Generate movie recommendations for each user as follows.
For each user u:
a. Find u’s n most similar neighbors
i. Compute the Jaccard similarity between u and all other users
ii. Select the n users with the highest similarity values. Call
these n users the
neighbors of u.
b. Compute movie recommendation scores for u as follows.
i. For each movie, compute its recommendation score using the
rating information
for the neighbors of u.
ii. Select the m movies with the highest recommendation scores.
System Design:
1. The system 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.
4. The system will contain a generic Recommender class that
can be used to represent the
basic information and behavior of any recommender technique.
Specifically, it will
contain the list of users, list of items, and an abstract method
for generating
recommendations. This class is abstract.
5. The system will contain a more specific recommender class,
UserCFRecommender, that
inherits from the generic Recommender class. It will contain
methods that are specific
to this recommendation technique.
UML Diagram for the System Design:
Recall the meanings of the UML Symbols:
- Private
+ Public
# Protected
Lab Work:
1. You are provided with the java files containing all the class
names along with the class variables
and the method definitions.
2. You are required to implement the class methods that are
shown in Bold Red in the UML diagram
above.
3. The algorithm for each method is written, and commented,
inside each method in the java files.
4. 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.
5. In your main method, create a UserCFRecommender object,
and use it to read the items and users
files. Then, print the user and item information to the console.
The users and items files are also
provided with the lab materials.
6. Run your main function and make sure that it is properly
reading the users and items information.
Lab Deliverables:
1. Zip all your code, along with a screen shot showing the
output obtained after you compiled and
run your code.
Movie.txt
1 , Toy story , Adventure Animation
2 , Jumanji , Adventure Fantasy
3 , Grumpy Old Men , Comedy Romance
4 , Waiting to Exhale , Comedy Drama Romance
5 , Father of the Bride Part II , Comedy
6 , Heat , Action Crime Thriller
7 , Sabrina , Comedy Romance
8 , Tom and Huck , Adventure Children
9 , Sudden Death , Action
10 , GoldenEye , Action Adventure Thriller
11 , The American President , Comedy Drama Romance
12 , Dracula: Dead and Loving It , Comedy Horror
13 , Balto , Animation Children
14 , Nixon , Drama
15 , Cutthroat Island , Action Adventure Romance
16 , Casino , Crime Drama
17 , Sense and Sensibility , Comedy Drama Romance
18 , Four Rooms , Comedy Drama Thriller
19 , Ace Ventura: When Nature Calls , Comedy
20 , Money Train , Action Comedy Crime Drama Thriller
item.java
abstract public class Item{ //data protected int ID;
protected String name; protected String description;
//methods public Item() { ID = -1; name =
""; description = ""; } public Item(int ID, String n,
String d) { this.ID = ID; this.name = n;
this.description = d; } public int get_ID() {return ID;}
public void set_ID(int i) {ID = i;} public String
get_name() {return name;} public void set_name(String i)
{name = i;} public String get_desciption() {return
description;} public void set_description(String i)
{description = i;}}
movie.java
public class Movie extends Item{ private String genre;
private String director; //methods public Movie(int id,
String n, String d, String g, String dir) { super(id, n,
d); genre = g; director = dir; } public void
set_genre(String g) {genre = g;} public String
get_genre(String g) {return genre;} public void
set_director(String g) {director = g;} public String
get_director(String g) {return director;}}
RecApp.java
public class RecApp{ public static void main(String[] args)
{ UserCFRecommender ucf = new
UserCFRecommender("", "movies.txt"); }}
Recommender.java
import java.util.Scanner;import java.io.*;public abstract class
Recommender{ protected User[] users = new User[10];
protected Item[] items = new Item[10];
//=========================
//========================= //reads items from a
file protected void read_items(String file_name) { /*
1. Open the file 2. Read file line by line
3. For each line, Extract ID, Name, & Genre
Create a Movie object Set Item ID,
Name & Genre Add the Movie object into the Items[]
items 6. Close the file */ try {
File f = new File(file_name);
Scanner s = new Scanner(f);
while(s.hasNext()) { String[]
vals = (s.nextLine()).split(" , "); for(int i=0;
i< vals.length; i++)
System.out.println(vals[i]);
System.out.println(); } }
catch (FileNotFoundException e) {} }
//=========================
//========================= protected void
read_users(String file_name) { /* 1. Open the
file 2. Read file line by line 3. For each line,
Extract ID, n_items For i = 0 to n_items
Extract the Movie IDs Create a
User Object Set User ID, n_items, and add all
items to that user. Add the User object into the
Users[] users 4. Close the file */ }
//=========================
//========================= public User[]
get_users() { return users; }
//=========================
//========================= public Item[]
get_items() { return items; }
//=========================
//========================= public abstract void
make_recommendations();}
UserCFRecommender.java
public class UserCFRecommender extends Recommender{
public UserCFRecommender() {} public
UserCFRecommender(String ufile, String ifile) {
read_items(ifile); read_users(ufile); }
//computes the Jaccard similarity between two users give
the //indices of both users in the Users[] users list. public
double compute_jaccard_sim(int u1_ind, int u2_ind) {
//1. get n_common_items: int n_common_items =
(users[u1_ind]).similarity(users[u2_ind]); //2. get
total_n_items using u1 n_items, u2 n_items & n_common_items
//3. compute Jaccard sim as
n_common_items/total_n_items return 0; } //finds
the nieghbors of a user given the user index in the //Users[]
users, and given the number of neighbors//returns neighbors
indices, and neighbors similarity values public void
find_user_neighbors(int u_ind, int n_neighbors, int[] n_ind,
double[] n_sim) { /* 1. Create an array
sim[] with size = n_users to save all similarity
values in 2. For each other user u compute
similarity between u_ind and u by calling the
compute_jaccard_sim method, and save the result in sim[u]
3. Scan sim[] and select the "n_neighbors" users with
the highest similarities. for i = 0 -> n_neighbors -1:
ind = -1 max = -1
for j = 0 -> n_users -1: if
sim[j]>max: max = sim[j]
ind = j save max & ind
into n_sim[i] and n_ind[i] set sim[ind] = -2
*/ } // public void
compute_recommendation_scores(int u_ind, int[] n_ind,
double[] n_sim, double[] scores) { } // public void
make_recommendations() {}}
users.txt
1 4 1 2 10 192 3 1 6 193 3 1 2 74 2 1 105 4 1 5 7 116 6 1 7 11
18 19 207 5 1 2 7 11 178 5 5 9 11 16 199 7 1 2 3 6 9 10 1910 5
1 2 10 18 1911 3 1 2 1612 7 1 2 3 5 10 11 1913 9 1 2 3 5 10 11
13 19 2014 5 2 6 16 17 1915 6 1 3 5 6 10 16
User.java
public class User{ //data private int ID; private String
name; private int n_items; private int[] items = new
int[100]; //methods public User() { ID = -1;
name = ""; n_items = 0; } public User(int
id, String n) { ID = id; name = n; n_items
= 0; } public void add_item(int i) {
items[n_items] = i; n_items++; } //computes
the number of common items between this and u. public int
similarity(User u) { int n = u.get_n_items();
int[] uitems = u.get_items(); int sim = 0;
for(int i=0; i<n; i++) for(int j=0; j<n_items;
j++) if(uitems[i] == items[j]){
sim++; break; }
return sim; } public int get_ID() {return ID;}
public int[] get_items() {return items;} public int
get_n_items() {return n_items;} public int set_ID(int i)
{ID = i;}}
Lab 8 User-CF Recommender System – Part I 50 points .docx

More Related Content

DOCX
Gym Management System User Manual
PDF
Connecting your Python App to OpenERP through OOOP
PPTX
Object Oriented Programming using C++: Ch06 Objects and Classes.pptx
PPT
Java căn bản - Chapter7
PPT
Chapter 7 - Defining Your Own Classes - Part II
PPT
Level 4
DOCX
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
PPT
14. Defining Classes
Gym Management System User Manual
Connecting your Python App to OpenERP through OOOP
Object Oriented Programming using C++: Ch06 Objects and Classes.pptx
Java căn bản - Chapter7
Chapter 7 - Defining Your Own Classes - Part II
Level 4
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
14. Defining Classes

Similar to Lab 8 User-CF Recommender System – Part I 50 points .docx (20)

PDF
ClassesandObjects
PDF
ClassesandObjects
PDF
ClassesandObjects
PDF
OOPs Interview Questions PDF By ScholarHat
PDF
Hi, I need help with a java programming project. specifically practi.pdf
PPTX
Class as the Basis of all Computation.pptx
PPT
Defining classes-and-objects-1.0
PPT
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
PPTX
Classes, Inheritance ,Packages & Interfaces.pptx
PDF
Django Good Practices
PPTX
Java For Automation
PPTX
3.Syntax.pptx for oops programing language
PPT
Chap08
PDF
Introduction to Recommender System
PDF
Programming II hiding, and .pdf
PPTX
Lecture01 object oriented-programming
PPTX
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
PDF
Java Software Solutions Foundations of Program Design 7th Edition Lewis Solut...
DOCX
Java oop concepts
ClassesandObjects
ClassesandObjects
ClassesandObjects
OOPs Interview Questions PDF By ScholarHat
Hi, I need help with a java programming project. specifically practi.pdf
Class as the Basis of all Computation.pptx
Defining classes-and-objects-1.0
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
Classes, Inheritance ,Packages & Interfaces.pptx
Django Good Practices
Java For Automation
3.Syntax.pptx for oops programing language
Chap08
Introduction to Recommender System
Programming II hiding, and .pdf
Lecture01 object oriented-programming
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
Java Software Solutions Foundations of Program Design 7th Edition Lewis Solut...
Java oop concepts
Ad

More from smile790243 (20)

DOCX
PART B Please response to these two original posts below. Wh.docx
DOCX
Part C Developing Your Design SolutionThe Production Cycle.docx
DOCX
PART A You will create a media piece based around the theme of a.docx
DOCX
Part 4. Implications to Nursing Practice & Implication to Patien.docx
DOCX
PART AHepatitis C is a chronic liver infection that can be e.docx
DOCX
Part A post your answer to the following question1. How m.docx
DOCX
PART BPlease response to these two original posts below..docx
DOCX
Part A (50 Points)Various men and women throughout history .docx
DOCX
Part A1. K2. D3. N4. C5. A6. O7. F8. Q9. H10..docx
DOCX
Part A Develop an original age-appropriate activity for your .docx
DOCX
Part 3 Social Situations2. Identify multicultural challenges th.docx
DOCX
Part A (1000 words) Annotated Bibliography - Create an annota.docx
DOCX
Part 6 Disseminating Results Create a 5-minute, 5- to 6-sli.docx
DOCX
Part 3 Social Situations • Proposal paper which identifies multicul.docx
DOCX
Part 3 Social Situations 2. Identify multicultural challenges that .docx
DOCX
Part 2The client is a 32-year-old Hispanic American male who c.docx
DOCX
Part 2For this section of the template, focus on gathering deta.docx
DOCX
Part 2 Observation Summary and Analysis • Summary paper of observat.docx
DOCX
Part 2 Observation Summary and Analysis 1. Review and implement any.docx
DOCX
Part 2Data collectionfrom your change study initiative,.docx
PART B Please response to these two original posts below. Wh.docx
Part C Developing Your Design SolutionThe Production Cycle.docx
PART A You will create a media piece based around the theme of a.docx
Part 4. Implications to Nursing Practice & Implication to Patien.docx
PART AHepatitis C is a chronic liver infection that can be e.docx
Part A post your answer to the following question1. How m.docx
PART BPlease response to these two original posts below..docx
Part A (50 Points)Various men and women throughout history .docx
Part A1. K2. D3. N4. C5. A6. O7. F8. Q9. H10..docx
Part A Develop an original age-appropriate activity for your .docx
Part 3 Social Situations2. Identify multicultural challenges th.docx
Part A (1000 words) Annotated Bibliography - Create an annota.docx
Part 6 Disseminating Results Create a 5-minute, 5- to 6-sli.docx
Part 3 Social Situations • Proposal paper which identifies multicul.docx
Part 3 Social Situations 2. Identify multicultural challenges that .docx
Part 2The client is a 32-year-old Hispanic American male who c.docx
Part 2For this section of the template, focus on gathering deta.docx
Part 2 Observation Summary and Analysis • Summary paper of observat.docx
Part 2 Observation Summary and Analysis 1. Review and implement any.docx
Part 2Data collectionfrom your change study initiative,.docx
Ad

Recently uploaded (20)

PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Pre independence Education in Inndia.pdf
PDF
Classroom Observation Tools for Teachers
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Institutional Correction lecture only . . .
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Basic Mud Logging Guide for educational purpose
PDF
Insiders guide to clinical Medicine.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
01-Introduction-to-Information-Management.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
RMMM.pdf make it easy to upload and study
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
human mycosis Human fungal infections are called human mycosis..pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pre independence Education in Inndia.pdf
Classroom Observation Tools for Teachers
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Institutional Correction lecture only . . .
VCE English Exam - Section C Student Revision Booklet
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Basic Mud Logging Guide for educational purpose
Insiders guide to clinical Medicine.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
01-Introduction-to-Information-Management.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Abdominal Access Techniques with Prof. Dr. R K Mishra
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
RMMM.pdf make it easy to upload and study

Lab 8 User-CF Recommender System – Part I 50 points .docx

  • 1. Lab 8 User-CF Recommender System – Part I 50 points In this lab, we will focus on understanding the design of a user- based collaborative filtering recommender system. Then we will implement half that design in this lab, and the other half in the next lab. System Description: A user-based collaborative filtering (User-CF for short) recommender works by making use of the similarities between users in a system. To recommend items for a specific user u, first User-CF finds the n-most similar users to u. These are called the neighbors of u. Then, the items that ratings that were given by the neighbors of u for the different items are used to generate recommendation scores for each item. Finally, the m items with the highest recommendation scores are recommended to u. The number of neighbors n, and the number of items m can vary based on the application in which the recommender is
  • 2. used. The overall flow of the user-based collaborative filtering recommendation process can be summarized in these steps: 1. Read movie information from file 2. Read user information from file 3. Generate movie recommendations for each user as follows. For each user u: a. Find u’s n most similar neighbors i. Compute the Jaccard similarity between u and all other users ii. Select the n users with the highest similarity values. Call these n users the neighbors of u. b. Compute movie recommendation scores for u as follows. i. For each movie, compute its recommendation score using the rating information for the neighbors of u. ii. Select the m movies with the highest recommendation scores. System Design: 1. The system will include a class named User to represent a
  • 3. 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. 4. The system will contain a generic Recommender class that can be used to represent the basic information and behavior of any recommender technique. Specifically, it will contain the list of users, list of items, and an abstract method for generating recommendations. This class is abstract. 5. The system will contain a more specific recommender class, UserCFRecommender, that
  • 4. inherits from the generic Recommender class. It will contain methods that are specific to this recommendation technique. UML Diagram for the System Design: Recall the meanings of the UML Symbols: - Private + Public # Protected Lab Work: 1. You are provided with the java files containing all the class names along with the class variables and the method definitions. 2. You are required to implement the class methods that are shown in Bold Red in the UML diagram above. 3. The algorithm for each method is written, and commented, inside each method in the java files. 4. Don’t forget to implement a constructor for each class to
  • 5. initialize its data. Let your constructor print a message indicating successful initialization of the object data. 5. In your main method, create a UserCFRecommender object, and use it to read the items and users files. Then, print the user and item information to the console. The users and items files are also provided with the lab materials. 6. Run your main function and make sure that it is properly reading the users and items information. Lab Deliverables: 1. Zip all your code, along with a screen shot showing the output obtained after you compiled and run your code. Movie.txt 1 , Toy story , Adventure Animation 2 , Jumanji , Adventure Fantasy 3 , Grumpy Old Men , Comedy Romance 4 , Waiting to Exhale , Comedy Drama Romance 5 , Father of the Bride Part II , Comedy 6 , Heat , Action Crime Thriller 7 , Sabrina , Comedy Romance 8 , Tom and Huck , Adventure Children 9 , Sudden Death , Action
  • 6. 10 , GoldenEye , Action Adventure Thriller 11 , The American President , Comedy Drama Romance 12 , Dracula: Dead and Loving It , Comedy Horror 13 , Balto , Animation Children 14 , Nixon , Drama 15 , Cutthroat Island , Action Adventure Romance 16 , Casino , Crime Drama 17 , Sense and Sensibility , Comedy Drama Romance 18 , Four Rooms , Comedy Drama Thriller 19 , Ace Ventura: When Nature Calls , Comedy 20 , Money Train , Action Comedy Crime Drama Thriller item.java abstract public class Item{ //data protected int ID; protected String name; protected String description; //methods public Item() { ID = -1; name = ""; description = ""; } public Item(int ID, String n, String d) { this.ID = ID; this.name = n; this.description = d; } public int get_ID() {return ID;} public void set_ID(int i) {ID = i;} public String get_name() {return name;} public void set_name(String i) {name = i;} public String get_desciption() {return description;} public void set_description(String i) {description = i;}} movie.java public class Movie extends Item{ private String genre; private String director; //methods public Movie(int id, String n, String d, String g, String dir) { super(id, n, d); genre = g; director = dir; } public void set_genre(String g) {genre = g;} public String get_genre(String g) {return genre;} public void set_director(String g) {director = g;} public String
  • 7. get_director(String g) {return director;}} RecApp.java public class RecApp{ public static void main(String[] args) { UserCFRecommender ucf = new UserCFRecommender("", "movies.txt"); }} Recommender.java import java.util.Scanner;import java.io.*;public abstract class Recommender{ protected User[] users = new User[10]; protected Item[] items = new Item[10]; //========================= //========================= //reads items from a file protected void read_items(String file_name) { /* 1. Open the file 2. Read file line by line 3. For each line, Extract ID, Name, & Genre Create a Movie object Set Item ID, Name & Genre Add the Movie object into the Items[] items 6. Close the file */ try { File f = new File(file_name); Scanner s = new Scanner(f); while(s.hasNext()) { String[] vals = (s.nextLine()).split(" , "); for(int i=0; i< vals.length; i++) System.out.println(vals[i]); System.out.println(); } } catch (FileNotFoundException e) {} } //========================= //========================= protected void read_users(String file_name) { /* 1. Open the file 2. Read file line by line 3. For each line, Extract ID, n_items For i = 0 to n_items Extract the Movie IDs Create a User Object Set User ID, n_items, and add all items to that user. Add the User object into the
  • 8. Users[] users 4. Close the file */ } //========================= //========================= public User[] get_users() { return users; } //========================= //========================= public Item[] get_items() { return items; } //========================= //========================= public abstract void make_recommendations();} UserCFRecommender.java public class UserCFRecommender extends Recommender{ public UserCFRecommender() {} public UserCFRecommender(String ufile, String ifile) { read_items(ifile); read_users(ufile); } //computes the Jaccard similarity between two users give the //indices of both users in the Users[] users list. public double compute_jaccard_sim(int u1_ind, int u2_ind) { //1. get n_common_items: int n_common_items = (users[u1_ind]).similarity(users[u2_ind]); //2. get total_n_items using u1 n_items, u2 n_items & n_common_items //3. compute Jaccard sim as n_common_items/total_n_items return 0; } //finds the nieghbors of a user given the user index in the //Users[] users, and given the number of neighbors//returns neighbors indices, and neighbors similarity values public void find_user_neighbors(int u_ind, int n_neighbors, int[] n_ind, double[] n_sim) { /* 1. Create an array sim[] with size = n_users to save all similarity values in 2. For each other user u compute similarity between u_ind and u by calling the compute_jaccard_sim method, and save the result in sim[u] 3. Scan sim[] and select the "n_neighbors" users with the highest similarities. for i = 0 -> n_neighbors -1:
  • 9. ind = -1 max = -1 for j = 0 -> n_users -1: if sim[j]>max: max = sim[j] ind = j save max & ind into n_sim[i] and n_ind[i] set sim[ind] = -2 */ } // public void compute_recommendation_scores(int u_ind, int[] n_ind, double[] n_sim, double[] scores) { } // public void make_recommendations() {}} users.txt 1 4 1 2 10 192 3 1 6 193 3 1 2 74 2 1 105 4 1 5 7 116 6 1 7 11 18 19 207 5 1 2 7 11 178 5 5 9 11 16 199 7 1 2 3 6 9 10 1910 5 1 2 10 18 1911 3 1 2 1612 7 1 2 3 5 10 11 1913 9 1 2 3 5 10 11 13 19 2014 5 2 6 16 17 1915 6 1 3 5 6 10 16 User.java public class User{ //data private int ID; private String name; private int n_items; private int[] items = new int[100]; //methods public User() { ID = -1; name = ""; n_items = 0; } public User(int id, String n) { ID = id; name = n; n_items = 0; } public void add_item(int i) { items[n_items] = i; n_items++; } //computes the number of common items between this and u. public int similarity(User u) { int n = u.get_n_items(); int[] uitems = u.get_items(); int sim = 0; for(int i=0; i<n; i++) for(int j=0; j<n_items; j++) if(uitems[i] == items[j]){ sim++; break; } return sim; } public int get_ID() {return ID;} public int[] get_items() {return items;} public int get_n_items() {return n_items;} public int set_ID(int i) {ID = i;}}