Question

Netflix Database - PROGRAMMED IN JAVA PLEASE :) In this program, you will build a Netflix...

Netflix Database - PROGRAMMED IN JAVA PLEASE :)

In this program, you will build a Netflix movie database using the provided file, netflix.csv. The file contains more than two hundred records of movies and TV programs, with each record consisting a title, a rating, a release year, and a user rated score.

There are three classes that you will need to implement: Movie, NetflixHandler, and NetflixApp.

Class: Movie

Movie

- title: String

- rating: String

- year: int

- score: int

+ Movie (String title, String rating, int year, int score)

+ getTitle(): String

+ getRating(): String

+ getYear(): int

+ getScore(): int

+ toString(): String

Instance variables:

- title: Title of a movie or TV program.

- rating: Rating of a movie or TV program. E.x.: R or PG-13

- year: Year of release.

- score: User rated score.

Methods:

- Movie (String title, String rating, int year, int score): An overloaded constructor.

- Getters for all the instance variables.

- toString(): It returns a string of information: title year rating score

Class: NetflixHandler

NetflixHandler

- data: Movie[]

- actualSize: int

+ SIZE: int = 500

+ NetflixHandler ()

+ read (String filePath): void

+ displayAllMovies (): void

+ searchTitle (): void

+ searchYear (): void

+ sort (Movie[] movies, int size): void

+ makeRecommendations(): void

Instance variables and constants:

- data: It is an array of Movie objects.

- actualSize: It is the real number of Movie objects in a partially filled array.

- SIZE: A constant that is set to be 500.

Methods:

- NetflixHandler (): The default constructor that initializes the instance variable, data, to a Movie array that has a size of 500.

- read (): This method opens the given file, netflix.csv, and reads it. While reading the file line by line, it also creates a Movie object and saves it into data.

- displayAllMovies (): This method loops through all the Movie objects saved in data and display their information.

- searchTitle (): This method looks for a movie that matches the title provided by a user.

- searchYear (): This method looks for a group of movies that match the release year given by a user.

- sort (Movie[] movies, int size): This method sorts a given Movie array, movies, using the provided size. It sorts the array into a descending order based on the user rated score.

- makeRecommendations (): This method makes recommendations to a user based on two options. Option one: It finds the top-5 movies, based on the user rated score, under a certain rating. The method then writes those 5 movies into a file, “top_5_movies.txt”. Option two: It finds the top-20 movies, based on the score only. The method then writes those 20 movies in to a file, “top_20_movies.txt”.

Class: NetflixApp

This is the main class. It has a private and static method, menu, which displays a menu that contains several choices (Please see the expected outcomes file for more details.). The main method should create a NetflixHandler object and let it call the read method before taking any choices.

Submission

Zip your .java source files for all the classes together into a zip file.

Name the zip file with your initials and Program 7

Example format: KES-Program7.zip

__________________________________________________________________________

Output:

Welcome to the Netflix Database

==========================================

1. Browse all movies.

2. Search a movie based on title.

3. Search movies based on year.

4. Top movies recommendation.

5. Exit.

==========================================

Please make your choice: 8

Please provide a valid input: 9

Please provide a valid input: 1

Title Year Rating Score

White Chicks 2004 PG-13 82

Grey's Anatomy 2016 TV-14 98

Prison Break 2008 TV-14 98

How I Met Your Mother 2014 TV-PG 94

Supernatural 2016 TV-14 95

Breaking Bad 2013 TV-MA 97

The Vampire Diaries 2017 TV-14 91

The Walking Dead 2015 TV-MA 98

Pretty Little Liars 2016 TV-14 96

Once Upon a Time 2016 TV-PG 98

Sherlock 2016 TV-14 95

Death Note 2006 TV-14 77

Naruto 2008 TV-PG 88

Arrow 2015 TV-14 96

. . . .

. . . .

. . . .

Welcome to the Netflix Database

==========================================

1. Browse all movies.

2. Search a movie based on title.

3. Search movies based on year.

4. Top movies recommendation.

5. Exit.

==========================================

Please make your choice: 2

Please provide a title: jackass

The title does not match any of the movies.

Welcome to the Netflix Database

==========================================

1. Browse all movies.

2. Search a movie based on title.

3. Search movies based on year.

4. Top movies recommendation.

5. Exit.

==========================================

Please make your choice: 2

Please provide a title: honey i shrunk the kids

Title Year Rating Score

Honey I Shrunk the Kids 1989 PG 80

Welcome to the Netflix Database

==========================================

1. Browse all movies.

2. Search a movie based on title.

3. Search movies based on year.

4. Top movies recommendation.

5. Exit.

==========================================

Please make your choice: 3

Please provide a year: 2020

The year does not match any of the movies.

Welcome to the Netflix Database

==========================================

1. Browse all movies.

2. Search a movie based on title.

3. Search movies based on year.

4. Top movies recommendation.

5. Exit.

==========================================

Please make your choice: 3

Please provide a year: 1997

Title Year Rating Score

Flubber 1997 PG 83

The Magic School Bus 1997 TV-Y 81

Anastasia 1997 G 93

Missione Hamburger 1997 PG 75

Animaniacs 1997 TV-Y7 72

Welcome to the Netflix Database

==========================================

1. Browse all movies.

2. Search a movie based on title.

3. Search movies based on year.

4. Top movies recommendation.

5. Exit.

==========================================

Please make your choice: 4

Do you want the recommendations based on ratings or scores?

1. Ratings

2. Scores

Please choose 1 or 2: 5

Please provide a valid input: 6

Please provide a valid input: 1

Please provide a rating: n/a

The rating does not match any of the movies.

Welcome to the Netflix Database

==========================================

1. Browse all movies.

2. Search a movie based on title.

3. Search movies based on year.

4. Top movies recommendation.

5. Exit.

==========================================

Please make your choice: 4

Do you want the recommendations based on ratings or scores?

1. Ratings

2. Scores

Please choose 1 or 2: 1

Please provide a rating: r

Recommendations made successfully! Top 5 movies found!

Welcome to the Netflix Database

==========================================

1. Browse all movies.

2. Search a movie based on title.

3. Search movies based on year.

4. Top movies recommendation.

5. Exit.

==========================================

Please make your choice: 4

Do you want the recommendations based on ratings or scores?

1. Ratings

2. Scores

Please choose 1 or 2: 2

Recommendations made successfully! Top 20 movies found!

Welcome to the Netflix Database

==========================================

1. Browse all movies.

2. Search a movie based on title.

3. Search movies based on year.

4. Top movies recommendation.

5. Exit.

==========================================

Please make your choice: 5

Thank you for using the database. Please come back next time.

_______________________________________________

Netflix.csv:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for the above assignment

There are 3 files which contain the code.

Feel free to comment on any doubt and give thumbs up!

Code for Movie.java

class Movie {

// private data members

private String title;

private String rating;

private int year;

private int score;

// constructor

public Movie(String title, String rating, int year, int score) {

this.rating = rating;

this.score = score;

this.title = title;

this.year = year;

}

// getters

public String getTitle() {

return title;

}

public String getRating() {

return rating;

}

public int getYear() {

return year;

}

public int getScore() {

return score;

}

// to String method

public String toString() {

return title + " " + year + " " + rating + " " + score;

}

}

Code for NetflixHandler.java

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.Console;

import java.io.File;

import java.io.FileReader;

import java.io.FileWriter;

import java.util.Scanner;

class NetflixHandler {

private Movie[] data;

private int actualSize;

private final int SIZE = 500;

public NetflixHandler() {

data = new Movie[SIZE];

actualSize = 0;

}

public void read(String filePath) {

try {

BufferedReader br = new BufferedReader(new FileReader(filePath));

String line;

while ((line = br.readLine()) != null) {

String[] str = line.split(",");

String title = str[0];

int year = Integer.parseInt(str[1]);

String rating = str[2];

int score = Integer.parseInt(str[3]);

data[actualSize] = new Movie(title, rating, year, score);

actualSize += 1;

}

br.close();

} catch (Exception e) {

System.out.println("Error! File not found!");

return;

}

}

public void displayAllMovies() {

for (int i = 0; i < actualSize; ++i) {

System.out.println(data[i].toString());

}

}

public void searchTitle() {

Console con = System.console();

System.out.println("Please provide a title:");

String titlee = con.readLine();

boolean flag = false;

boolean firstEntry = false;

for (int i = 0; i < actualSize; ++i) {

if (data[i].getTitle().equalsIgnoreCase(titlee)) {

if (firstEntry == false) {

System.out.println("Title Year Rating Score");

firstEntry = true;

}

System.out.println(data[i].toString());

flag = true;

}

}

if (flag == false) {

System.out.println("The title does not match any of the movies.");

}

}

public void searchYear() {

Console con = System.console();

int year;

while (true) {

System.out.println("Please provide a year: ");

try {

year = Integer.parseInt(con.readLine());

break;

} catch (Exception e) {

System.out.println("Error! Enter a valid year");

}

}

boolean flag = false;

boolean firstEntry = false;

for (int i = 0; i < actualSize; ++i) {

if (data[i].getYear() == year) {

if (firstEntry == false) {

System.out.println("Title Year Rating Score");

firstEntry = true;

}

System.out.println(data[i].toString());

flag = true;

}

}

if (flag == false) {

System.out.println("The year does not match any of the movies.");

}

}

public void sort(Movie[] movies, int size) {

for (int i = 0; i < size; ++i) {

boolean flag = false;

for (int j = 0; j < size - 1; ++j) {

if (movies[j].getScore() > movies[j + 1].getScore()) {

Movie temp = movies[j];

movies[j] = movies[j + 1];

movies[j + 1] = temp;

flag = true;

}

}

if (flag == false) {

break;

}

}

}

public void makeRecommendations() {

System.out.println("Do you want the recommendations based on ratings or scores?\n1. Ratings\n2. Scores");

int option;

Console con = System.console();

while (true) {

try {

option = Integer.parseInt(con.readLine());

if (option == 1 || option == 2) {

break;

} else {

System.out.println("Please provide a valid input: ");

}

} catch (Exception e) {

e.printStackTrace();

System.out.println("Error! Enter a valid number");

}

}

if (option == 1) {

System.out.println("Please provide a rating: ");

String rating = con.readLine();

boolean flag = false;

Movie[] tempArray = new Movie[SIZE];

int tempSize = 0;

for (int i = 0; i < actualSize; ++i) {

if (data[i].getRating().equalsIgnoreCase(rating)) {

tempArray[tempSize] = data[i];

tempSize++;

flag = true;

}

}

if (flag == false) {

System.out.println("The rating does not match any of the movies.");

return;

}

sort(tempArray, tempSize);

String outputFileName = "top_5_movies.txt";

try {

BufferedWriter bw = new BufferedWriter(new FileWriter(new File(outputFileName)));

for (int i = tempSize - 1; i >= tempSize - 5; --i) {

bw.write(tempArray[i].toString() + "\n");

}

System.out.println("Recommendations made successfully! Top 5 movies found!");

bw.close();

} catch (Exception e) {

System.out.println("Error! Cannot able to create file!");

return;

}

} else {

String outputFileName = "top_20_movies.txt";

sort(data, actualSize);

try {

BufferedWriter bw = new BufferedWriter(new FileWriter(new File(outputFileName)));

for (int i = actualSize - 1; i >= actualSize - 20; --i) {

bw.write(data[i].toString() + "\n");

}

System.out.println("Recommendations made successfully! Top 20 movies found!");

bw.close();

} catch (Exception e) {

System.out.println("Error while creating file");

}

}

}

}

Code for NetflixApp.java

import java.io.Console;

import java.util.Scanner;

public class NetflixApp {

public static void main(String[] args) {

Console con = System.console();

NetflixHandler handler = new NetflixHandler();

handler.read("movies.csv");

while (true) {

System.out.println(" Welcome to the Netflix Database");

System.out.println("==========================================");

System.out.println("1. Browse all movies.");

System.out.println("2. Search a movie based on title.");

System.out.println("3. Search movies based on year.");

System.out.println("4. Top movies recommendation");

System.out.println("5. Exit.");

System.out.println("==========================================");

System.out.print("Please make your choice: ");

int choice = 0;

try {

con.flush();

choice = Integer.parseInt(con.readLine());

if (choice < 1 || choice > 5) {

System.out.println("Error! Enter a valid choice!");

} else {

switch (choice) {

case 1:

handler.displayAllMovies();

break;

case 2:

handler.searchTitle();

break;

case 3:

handler.searchYear();

break;

case 4:

handler.makeRecommendations();

break;

case 5:

System.out.println("Thank you for using the database. Please come back next time.");

System.exit(1);

}

}

} catch (Exception e) {

e.printStackTrace();

System.out.println("Error! Enter a valid number!");

}

}

}

}

Screenshot

Thank You!

Add a comment
Know the answer?
Add Answer to:
Netflix Database - PROGRAMMED IN JAVA PLEASE :) In this program, you will build a Netflix...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this labwork, you are expected to write java program that assigns ratings to the movies (1-5). You are given the main class of the program(See Lectures). You supposed to write two classes that wor...

    In this labwork, you are expected to write java program that assigns ratings to the movies (1-5). You are given the main class of the program(See Lectures). You supposed to write two classes that works with main class. Movie Class has two attributes: title(String) . rating(int) Reviewer Class has one class variable (array of movies) and three methods: Setmovies: Allow the reviewer's movies to be set . . . rateMovie: Let the reviewer rate one of the movies. pickFavorite: pick...

  •    moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring>...

       moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring> using namespace std; typedef struct{ int id; char title[250]; int year; char rating[6]; int totalCopies; int rentedCopies; }movie; int loadData(ifstream &infile, movie movies[]); void printAll(movie movies[], int count); void printRated(movie movies[], int count); void printTitled(movie movies[], int count); void addMovie(movie movies[],int &count); void returnMovie(movie movies[],int count); void rentMovie(movie movies[],int count); void saveToFile(movie movies[], int count, char *filename); void printMovie(movie &m); int find(movie movies[], int...

  • Help! Not sure how to create this java program to run efficiently. Current code and assignment...

    Help! Not sure how to create this java program to run efficiently. Current code and assignment attached. Assignment :Write a class Movies.java that reads in a movie list file (movies.txt). The file must contain the following fields: name, genre, and time. Provide the user with the options to sort on each field. Allow the user to continue to sort the list until they enter the exit option. ---------------------------------------------------------- import java.util.*; import java.io.*; public class Movies { String movieTitle; String movieGenre;...

  • Need this in C++ Goals: Your task is to implement a binary search tree of linked...

    Need this in C++ Goals: Your task is to implement a binary search tree of linked lists of movies. Tree nodes will contain a letter of the alphabet and a linked list. The linked list will be an alphabetically sorted list of movies which start with that letter. MovieTree() ➔ Constructor: Initialize any member variables of the class to default ~MovieTree() ➔ Destructor: Free all memory that was allocated void printMovieInventory() ➔ Print every movie in the data structure in...

  • no buffered reader. no try catch statements. java code please. And using this super class: Medialtemjava...

    no buffered reader. no try catch statements. java code please. And using this super class: Medialtemjava a Create the "middle" of the diagram, the DVD and ForeignDVD classes as below: The DVD class will have the following attributes and behaviors: Attributes (in addition to those inherited from Medialtem): • director:String • rating: String • runtime: int (this will represent the number of minutes) Behaviors (methods) • constructors (at least 3): the default, the "overloaded" as we know it, passing in...

  • WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL...

    WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL PASTE AT BOTTOM MOVIES.CPP #include "movies.h" #include "Movie.h" Movies *Movies::createMovies(int max) { //dynamically create a new Movies structure Movies *myMovies = new Movies; myMovies->maxMovies = max; myMovies->numMovies = 0; //dynamically create the array that will hold the movies myMovies->moviesArray = new Movie *[max]; return myMovies; } void Movies::resizeMovieArray() { int max = maxMovies * 2; //increase size by 2 //make an array that is...

  • PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class...

    PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...

  • Java Programming Create a program named MovieTest The program will create 10 Movie objects and place...

    Java Programming Create a program named MovieTest The program will create 10 Movie objects and place them in an array or ArrayList of type Movie. The program must do the following (all in main): Create an array or ArrayList of type Movie. Use the data in the text file that is in the download for the Movie file to create 10 Movie objects. Store the 10 Movie objects in the array or ArrayList. You MUST use the date in the...

  • Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director,...

    Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director, Genre, Year Released, Running Time) into a vector of structures and perform the following operations: Search for a specific title Search for movies by a specific director Search for movies by a specific genre Search for movies released in a certain time period Search for movies within a range for running time Display the movies on the screen in a nice, easy to read...

  • C++ Language I have a class named movie which allows a movie object to take the...

    C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT