CSCI3901 Assignment1 Solved

30.00 $

Category:

Description

5/5 - (1 vote)

Get practice in decomposing a problem, creating a design for a program, and implementing and testing a program.

Background

Recommender systems use past behaviours of others to give you suggestions on what has worked for others in the past, based on your own current context. Amazon books, for example, looks at the set of books that you have already purchased and compares your reading list with the reading list of others. It then aggregates the purchases of others who also bought many of the same books as you and recommends to you those books from the aggregate that you haven’t already purchased. Typically, you don’t make a recommendation unless there is enough data to suggest that it’s a meaningful recommendation.

In this assignment, we will do a simplified version of a recommender system. In our case, you will be recommending courses to take at the university based on what other students have taken.

Problem

Design a class CourseSelector that collects data on which courses students have taken, and then allows a user to make queries about the data. You will be provided with a main program that will then let a user invoke the operations on the data.

Your class will read data from a file, then allow a user to request the following three queries:

  • Recommend n courses based on a given list of courses
  • Print to a file the number of students who have taken any pair of courses
  • Print to screen the number of students who have taken any pair of a given list of courses

Specifically, you will implement the following class:

class CourseSelector { public int read ( String filename ) { /∗ IMPLEMENT ∗/ }

public ArrayList<String> recommend( String taken ,

int support , int numRec)

{ /∗ IMPLEMENT ∗/ } public boolean showCommon( String          courses ) { /∗ IMPLEMENT ∗/ }

public boolean showCommonAll( String                               filename ) { /∗ IMPLEMENT ∗/ }

}

Descriptions of the methods follow below.

int read(String filename) The read method reads the contents of a file named filename to the object. Each line represents the courses a student has taken. The method returns the number of rows read in. The data should replace any data previously read into the class. Individual courses in a line are separated by spaces.

ArrayList<String> recommend(String taken, int support, int numRec) This method returns a list of numRec course recommendations given a list (taken) of courses already taken, separated by spaces. Only report courses if the recommendations are supported by at least support other students.

More specifically, the recommend method should

  1. Find all of the students who have taken all of the same courses listed in taken.
  2. If there are at least support students who have taken all the courses, then
    • Find all of the courses these students have taken, not including the courses listed in taken.
    • For each of these courses, count the number of times they appear
    • Report back the first numRec most taken courses

If you don’t have enough students to make a recommendation, then return null.

If you do have recommendations to return, then the returned ArrayList should have at most numRec in it. The courses should be provided in descending order of frequency. Two courses with the same frequency can be in any order.

There is one situation where the ArrayList can have more entries: when you reach numRec entries and there are other courses with the same frequency that you haven’t reported. Rather than choose between which of these last courses to return, report all of the ones with that frequency.

For example, suppose that the outcome of computation 2c is the following list of courses:

Course Number of students who have taken it
CSCI1100 12
CSCI2110 10
CSCI2112 8
CSCI2134 8
CSCI3110 5
CSCI3120 4
  • For 2 recommendations, return CSCI1100 and CSCI2110.
  • For 3 recommendations, return CSCI1100, CSCI2110, CSCI2112, and CSCI2134 (since the last two both have the same frequency).
  • For 5 recommendations, return CSCI1100, CSCI2110, CSCI2112, CSCI2134, and CSCI3110.

boolean showCommon(String courses) This method prints to the screen a 2d array with one row and column for each course in courses in the order in which they appear. The value in each entry is the number of students who have taken both courses. Return False if any errors were encountered and True otherwise.

boolean showCommonAll(String filename) This method prints to the file filename a 2d array with one row and column for every course that has been taken by any student, in order of course name. The value in each entry is the number of students who have taken both courses. Return False if any errors were encountered and True otherwise.

Both methods with this method name compute a pairwise popularity matrix. Pairs of courses that are both taken frequently shouldn’t be scheduled at the same time, so we want to know the pairs of courses that are both taken often.

The basic logic is as follows:

  1. Create a 2d array with one row and one column for each course that we are given.
  2. Consider the courses of each student in our system.
    • Find the rows/column number for each of the courses.
    • For each pair of courses, add 1 to the entry in the 2d array for the pair. Do not pair a course with itself.
  3. Print the resulting matrix.

When you print the matrix, you do not print the column names. For each row of the matrix, print the course name and then the integer from each column. Each of these bits to print will be separated by a tab character.

For example, suppose that we have entries for the following students in our system:

CSCI1110 CSCI2110 CSCI2122

CSCI2110 CSCI2112 CSCI2122 CSCI2134

CSCI1110 CSCI2134 CSCI3171

CSCI2141

If we asked for a matrix for all courses above, we would get the following output

CSCI1110 0 1 0 1 1 0 1
CSCI2110 1 0 1 2 1 0 0
CSCI2112 0 1 0 1 1 0 0
CSCI2122 1 2 1 0 1 0 0
CSCI2134 1 1 1 1 0 0 1
CSCI2141 0 0 0 0 0 0 0
CSCI3171

How to submit

1 0 0 0 1 0 0
  • Assignment_1-e41wal.zip