Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public ArrayList selectWhereMovieIs (String movie, ArrayList actorsInfo): Given a movie, returns the list of all actors in that movie Introduction to Software Development the movie

public ArrayList  selectWhereMovieIs (String movie, ArrayList  actorsInfo):  Given a movie, returns the list of all actors in that movie Introduction to Software Development  the movie is the name of a movie as a String  actorsInfo is the ArrayList to get the data from  Given a non-existent movie, this method should return an empty list

1. Class Movie Trivia:

import java.util.ArrayList;

import file.MovieDB; import movies.Actor; import movies.Movie;

/** * Movie trivia class providing different methods for querying and updating a movie database. */ public class MovieTrivia { /** * Create instance of movie database */ MovieDB movieDB = new MovieDB(); public static void main(String[] args) { //create instance of movie trivia class MovieTrivia mt = new MovieTrivia(); //setup movie trivia class mt.setUp("moviedata.txt", "movieratings.csv"); } /** * Sets up the Movie Trivia class * @param movieData .txt file * @param movieRatings .csv file */ public void setUp(String movieData, String movieRatings) { //load movie database files movieDB.setUp(movieData, movieRatings); //print all actors and movies this.printAllActors(); this.printAllMovies(); } /** * Prints a list of all actors and the movies they acted in. */ public void printAllActors () { System.out.println(movieDB.getActorsInfo()); } /** * Prints a list of all movies and their ratings. */ public void printAllMovies () { System.out.println(movieDB.getMoviesInfo()); } // TO DO add additional methods as specified in the instructions above }

________________________________________________________

package file;

import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.ArrayList;

import movies.Actor; import movies.Movie;

/** * Loads movie and ratings data from two given data files. * Creates two ArrayLists for storing the information in those data files. * */ public class MovieDB { /** * List of actors information. */ private ArrayList actorsInfo = new ArrayList(); /** * List of movies information. */ private ArrayList moviesInfo = new ArrayList(); /** * Loads and parses the given movieData and movieRatings data files. * @param movieData file to load and parse * @param movieRatings file to load and parse */ public void setUp (String movieData, String movieRatings) { //load movieData file try { File f = new File (movieData); FileReader fd = new FileReader(f); BufferedReader br = new BufferedReader(fd); while (true) { String line = br.readLine(); if (line == null) { break; } String [] array = line.trim().split(","); Actor newActor = new Actor (array[0].trim().toLowerCase()); for (int i = 1; i < array.length; i++) { newActor.getMoviesCast().add(array[i].trim().toLowerCase()); } actorsInfo.add(newActor); } fd.close(); br.close(); } catch (Exception e) { e.printStackTrace(); } //load movieRatings file try { File f = new File (movieRatings); FileReader fd = new FileReader(f); BufferedReader br = new BufferedReader(fd); while (true) { String line = br.readLine(); if (line == null) { break; } String [] array = line.trim().split(","); if (array[1].trim().charAt(0) >= '0' && array[1].trim().charAt(0) <= '9') { Movie newMovie = new Movie(array[0].trim().toLowerCase(), Integer.parseInt(array[1]), Integer.parseInt(array[2])); moviesInfo.add(newMovie); } } fd.close(); br.close(); } catch (Exception e) { e.printStackTrace(); } } /** * Get actors information. * @return list of actors */ public ArrayList getActorsInfo() { return this.actorsInfo; } /** * Get movies information. * @return list of movies */ public ArrayList getMoviesInfo() { return this.moviesInfo; }

} ---------------------------------------

Database: Move data:

Meryl Streep, Doubt, Sophie's Choice, The Post

Tom Hanks, The Post, Catch Me If You Can, Cast Away

Amy Adams, Doubt, Leap Year, Man of Steel, Arrival

Brandon Krakowsky

Robin Williams, Popeye

Brad Pitt, Seven, Fight Club

-----------------------------------

Database: move rating

movie,critics,audience

Doubt,79,78

Arrival,94,82

Jaws,97,90

Rocky II,91,95

Seven,29,29

Popeye,0,0

ET,85,86

Step by Step Solution

There are 3 Steps involved in it

Step: 1

For you to implement the selectWhereMovieIsmethod in the MovieTrivia class you can iterate through t... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions