Question
Add to this JAVA code the following: Task 4: Create an array that represents recommended ratings for the user. Now, there should be 20 numbers
Add to this JAVA code the following:
Task 4: Create an array that represents recommended ratings for the user. Now, there should be 20 numbers in this array, one for each movie. The higher the number, the more strongly your program thinks the user will like the movie. The number should be the average overall 30 ratings for the movie that are greater than 0 (only include ratings for users who have actually seen the movie). You can use some weighted calculations based on the similarity scores you generated in calculateSimilarityScore method.
Task 5: Display the name of the top movie (according to the recommended ratings from the previous step) that the user has not yet seen.
So currently, the program asks for a user to enter ratings for 20 movies (between 1-5, and -1 if user hasn't seen the movie) and then outputs a column for the list of movies, a column of the ratings the user entered, and a column of a similarity score. So basically, for task 4-- take an average of all of the ratings for a specific movie from the rating.txt file read, and display it in a column. Then for task 5, based on both these averages and the ratings a user has entered, display the name of the movie that has the highest ratings average (only considering the movies that the user has entered a -1 or has not seen)!
public static void main(String[] args) {
String movies[] = new String[20]; int movieRatings[][] = new int[30][20]; int userRatings[] = new int[20];
Scanner in = new Scanner(System.in);
String movieFileName, ratingsFileName;
System.out.print("Enter Movie File name: "); movieFileName = in.next();
System.out.print("Enter Ratins File name: "); ratingsFileName = in.next();
loadData(movieFileName, ratingsFileName, movies, movieRatings); System.out.print("Enter User ratings: ");
for (int i = 0; i < 20; i++) { while (true) { userRatings[i] = in.nextInt(); if (userRatings[i] >= -1 && userRatings[i] <= 5) { break; } System.out.println("User Rating must be 0 to 5 or -1 to unknown... Reenter..."); } }
double userRat = calculateScores(userRatings); double similarScores[] = calculateSimilarityScroes(userRatings, movieRatings); System.out.printf("%40s %12s \tMovie Ratings ", "Movie", "User Rating");
for (int i = 0; i < 20; i++) { System.out.printf("%40s %12d \t %.2f ", movies[i], userRatings[i], similarScores[i]); } }
public static void loadData(String moviesFileName, String ratingsFileName, String[] movies, int[][] movieRatings) { try { Scanner fin = new Scanner(new File(moviesFileName)); int i = 0; while (fin.hasNextLine()) { movies[i] = fin.nextLine(); i++; } fin.close(); fin = new Scanner(new File(ratingsFileName));
for (i = 0; i < 30; i++) { for (int j = 0; j < 20; j++) { movieRatings[i][j] = fin.nextInt(); } } } catch (FileNotFoundException e) { System.out.println("Unable to open file"); System.exit(1); } }
public static double calculateScores(int ratings[]) { int i, j; double avg = 0, max = ratings[0]; for (j = 0; j < 20; j++) { avg += ratings[j]; if (max < ratings[j]) { max = ratings[j]; } } avg = (double) avg / j; return avg / max; }
public static double[] calculateSimilarityScroes(int[] userRating, int[][] movieRatings) { double scores[] = new double[30]; int i, j; for (i = 0; i < 30; i++) { scores[i] = calculateScores(movieRatings[i]); } return scores; } }
The list of movies...must be read as a file Airplane Alien Bridesmaids Cloudy with a Chance of Meatballs Exorcist Fantastic Mr. Fox Forrest Gump Hangover Harold and Kumar Go to White Castle The Help Incredibles Jaws Monsters, Inc Psycho Raiders of the Lost Ark Silver Linings Playbook Titanic Twilight Eclipse Up Zoolander |
The movie ratings-- must be read as a file - 1 2 3 5 -1 5 3 3 1 4 2 2 5 -1 1 3 3 5 4 3 - 1 1 1 4 1 3 3 1 2 3 4 -1 4 1 2 4 5 4 2 3 3 -1 2 3 -1 2 5 -1 3 3 5 2 2 1 2 3 5 3 4 2 - 1 1 -1 4 1 3 5 2 1 5 3 -1 5 2 1 3 4 5 3 2 - 1 -1 3 2 -1 5 5 2 2 4 4 2 3 2 -1 3 4 4 3 1 2 1 1 5 2 2 4 2 3 4 3 -1 5 2 2 5 3 5 2 1 3 -1 3 4 -1 2 5 -1 -1 4 3 -1 3 -1 2 5 5 5 4 2 4 -1 4 2 3 -1 1 3 4 -1 1 4 4 4 -1 2 -1 1 4 4 4 3 3 3 -1 2 2 4 3 -1 2 4 3 4 2 -1 -1 2 2 3 3 -1 3 -1 3 4 -1 5 5 -1 -1 -1 1 -1 -1 1 1 2 -1 5 3 -1 3 4 3 4 -1 5 5 2 3 3 4 1 1 -1 -1 -1 -1 4 4 -1 4 4 1 3 -1 5 4 -1 1 3 4 1 -1 1 -1 1 -1 5 5 -1 3 1 4 3 -1 5 4 1 3 2 1 -1 4 2 1 -1 2 4 3 -1 5 1 4 4 2 5 5 1 2 3 1 1 -1 1 -1 1 -1 5 4 1 5 4 3 -1 1 3 4 -1 -1 3 3 -1 1 1 2 -1 3 5 - 1 1 1 3 -1 3 1 3 -1 -1 3 -1 5 2 2 1 4 -1 5 -1 3 -1 2 3 1 5 4 3 3 -1 5 -1 5 2 -1 4 4 3 3 3 1. 1 1 3 2 4 1 -1 -1 -1 5 -1 3 -1 -1 1 -1 2 5 2 - 1 2 3 5 -1 4 3 1 1 3 3 -1 4 -1 -1 4 3 2 5 1 - 1 1 3 3 -1 3 3 1 -1 -1 3 -1 5 -1 -1 3 1 2 4 -1 3 -1 2 4 1 4 3 -1 2 3 4 1 3 -1 2 -1 4 3 5 -1 - 1 1 3 5 -1 4 2 1 -1 3 3 2 3 2 -1 3 1 -1 3 -1 3 2 2 3 -1 5 -1 -1 2 3 4 -1 4 1 -1 -1 -1 -1 4 2 - 1 3 -1 -1 4 -1 2 -1 2 2 2 5 -1 3 4 -1 -1 2 -1 2 1. 4 3 -1 3 2 1 -1 -1 -1 1 3 1 3 3 1 -1 -1 -1 3 4 3 3 -1 4 2 -1 4 -1 -1 2 4 -1 3 4 2 -1 -1 -1 4 - 1 5 1 -1 4 1 -1 3 2 2 -1 4 1 3 3 1 -1 -1 -1 3 - 1 4 2 1 5 -1 -1 2 1 1 -1 5 -1 5 4 1 2 2 -1 1 2 5 2 -1 3 -1 -1 1 -1 2 -1 4 2 4 3 -1 2 1 -1 -1 2 5 1 1 4 -1 2 1 -1 -1 2 4 -1 3 4 2 -1 -1 -1 4 |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started