QuestionQuestion

In this project you will provide a tool for searching through the data set of movies that were filmed on location in San Francisco.

Objectives
The goal of this programming project is for you to master (or at least get practice on) the following tasks:
• working with multi-file programs
• reading data from input files
• using and understanding command line arguments
• working with large data sets
• using the ArrayList class

• writing classes
• working with existing code
• extending existing classes (inheritance)
• parsing data

Dataset
In this project you will be working with open data. Wikipedia has a good description of open data: ”Open data is the idea that some data should be freely available to everyone to use and republish as they wish, without restrictions from copyright, patents or other mechanisms of control.”
The data set that you need can be found at DataSF portal. For your convenience a csv file is also located on the course website. It      is a listing of filming locations of movies shot in San Francisco starting from 1924. The data set is provided by San Francisco Film Commission.
The file that you download is a CSV (comma separated values) file - it is a simple text file and is processed like text file (but it can also be opened by most of the spreadsheet programs and displayed column-wise based on the locations of commas on each line). Since some of the columns contain longer text that might, optionally, contain commas as well, those entries are enclosed in a set of double quotes.
There are eleven columns in the dataset. Some of the columns may be empty.

From the point of view of this assignment, a valid row in the data set MUST contain the title, year of release, location, and actor1 fields. Any rows that do not contain all of those fields should be quietly ignored by the program.

User Interface
Your program has to be a console based program (no graphical interface) - this means that the program should not open any windows or dialogs to prompt user for the input.

Program Usage
The program is started from the command line (or run within an IDE). It expects one command line argument.
This program should use command line arguments. When the user runs the program, they provide the name of the input file as a command line argument. (This way the user can specify a data set from another city or a different version of the data set).
The user may start the program from the command line or run it within an IDE like Eclipse - from the point of view of your program this does not matter.
If the name of the input file provided as a command line argument is incorrect or the file cannot be opened for any reason, the program should display an error message and terminate. It should not prompt the user for an alternative name of the file.
If the program is run without any arguments, the program should display an error message and terminate. It should not prompt the user for the name of the file.
The error messages should be specific and informative, for example:
Error: the file films.csv cannot be opened.
or
Usage Error: the program expects file name as an argument.
The above error messages generated by your code should be written to the System.err stream (not the System.out stream).2

Input and Output
The program should run in a loop that allows the user to issue different queries. The two types of queries are:
title KEYWORD
and
actor KEYWORD
In the first case, the program should display the list of all the movies in the data set whose title contains the given keyword (this search should be case insensitive). In the second case, the program should display the list of all the movies with actors whose names contain the given keyword (again, this search should be case insensitive). In both cases, the user may enter a multi-word KEYWORD.
On each iteration, the user should be prompted to enter a new query (for which the program computes the results) or the word ’quit’ to indicate the termination of the program.
The user should not be prompted for any other response.
If the query entered by the user is invalid, the program should display an error message:
This is not a valid query. Try again.
Allow the user to provide an alternative query.
If the query entered by the user does not return any results, the program should print a message
No matches found. Try again.
and allow the user to provide an alternative query.

2 If you are not sure what the difference is, research it or ask questions.

Matching reults display: If the query entered by the user matches one or more movies, the information about all the matching movies should be displayed in the following format:
All the words in uppercase letters are place-holders for the actual values from the data set. If any of the values is missing, it should be left blank and the corresponding commas and parenthesis should not be shown.

Sample interaction:
Sample user interaction is shown in Appendix 2.

Data Storage and Organization
You need to provide an implementation of several classes that store the data and compute the results when the program is executed.
In particular, your program must implement and use the following classes. You may implement additional classes and additional methods in the required classes, if you wish.

Actor Class
The Actor class is used to represent actors. It should store the name of an actor and it should provide a one parameter contructor. The constructor should throw an instance of IllegalArgumentException if it is called with a null prameter or an empty string parameter.

Location Class
The Location class is used to represent the filming locations and fun facts that may be associated with them. It should store the name of the location itself and the optional fun fact. The class should provide a constructor that takes as parameters two strings that represent the location and the fun fact, respectively. The constructor should throw an instance of IllegalArgumentException if it is called with the location string that is either null or empty. The fun fact is allowed to be null or empty (this will happen when there is no fun fact associated with the given location, i.e., the corresponding column in the data set is empty).

Movie Class
The Movie class is used to represent movies. It should store the following information:
• title
• year of release
• list of SF locations in which the movie was filmed (together with associated fun facts)
• director
• writer
• list of up to three actors
Note: most of the movies are represented on multiple rows of the data set.

This class should provide two constructors:
public Movie(String title, int year)
public Movie(String title, int year, String director, String writer,
Actor actor1, Actor actor2, Actor actor3)
The following describes acceptable values for each of the constructor parameters. If a constructor is called with an invalid parameter, it should throw an instance of IllegalArgumentException.
title - any non-empty string
year - a number between 1900 and 2020 (including both end points)
director - any non-empty string to indicate the name, null or an empty string when the data is not available (for example, when the column in the data set is empty)
• writer - any non-empty string to indicate the name, null or an empty string when the data is not available
• actor1 - an Actor object, (null is not an acceptable value)
• actor2 - an Actor object or null when the data is not available
• actor3 - an Actor object or null when the data is not available There should be no default constructor.
The class should provide a method
public void addLocation(Location loc)
that adds a given location to the list of filming locations for the current Movie object. The method should throw an instance of IllegalArgumentException if it is called with null parameter.
This class should implement Comparable<Movie> interface. The comparison should be done by the year of release as the primary key (earlier years are considered to be smaller), and by the title as the secondary key (i.e., when two objects that have the same value of year are compared, the comparison should be performed by title) (the titles should be ordered according to the same rules as the String objects and the comparison should be case insensitive).
This class should override the equals methods. The two Movie objects should be considered equal, if the tite and year are identical (the title comparison should be case insensitive).
This class should override the toString method. It should return a string matching the following format:
All the words in uppercase letters are place-holders for the actual values from the data set. If any of the values is missing, it should be left blank and the corresponding commas and parenthesis should not be shown. (This is the format used to display the results to the user.)
The class should provide getters and setters for any data fields that your program may need access to from the outside of the class.

MovieList Class
The MovieList class should be used to store all the Movie objects. This class should inherit from the ArrayList<Movie> class. The class needs to provide a default constructor that creates an empty MovieList object.

3A default constructor is one that can be used without passing any arguments.

The class should implement the following two methods:
public MovieList getMatchingTitles ( String keyword ) public MovieList getMatchingActor ( String keyword )
The first method should return a list of Movie objects whose titles contain the keyword as a substring. The second method should return a list of Movie object whose actors’ names contain the keyword as a substring. The cantainment should be determined in case insesitive way in both cases. The returned lists should be sorted according to the natural order4 of their elements. These methods should return null if the functions are called with a keyword that is either equal to null or an empty string. They should also return null if there are no matches for the keyword.
The class should override the toString method. This method should return a String containing a semi-colon and space separated list of the titles of the Movie objects stored in the list. For example, if the three Movie objects stored in the list arre On the Road, Budding Prospects, Pilot and The House on Telegraph Hill, than the returned String should be "On the Road; Budding Prospects, Pilot; The House on Telegraph Hill". You may implement other methods, if you wish.

SFMovieData Class
The SFMovieData class is the actual program. This is the class that should contain the main method. It is responsible for opening and reading the data files, obtaining user input, performing some data validation and handling all errors that may occur (in particular, it should handle any exceptions thrown by your other classes and terminate gracefully, if need be, with a friendly error message presented to the user).
You may implement other methods in this class to modularize the design.

Given Code
To simplify parsing of the data from the input file, you can use the function splitCSVLine. Given a row (a single line) from the input data set, it returns an ArrayList<String> object containing all the individual entries from that row. This function produces empty strings to represent entries that were blank within the input line before the last comma. If the last columns in the row are missing, the returned ArrayList<String> object has fewer entries.
For example: given a string containing the line:
"Alcatraz",2012,"Francisco St from Larkin to Polk",,"Bonanza Productions Inc.","Warner Bros. Television","J.J. Abrams ","Steven Lilien","Sarah Jones","Jorge Garcia",
it returns an ArrayList<String> object with ten strings:
["Alcatraz", "2012","Francisco St from Larkin to Polk","","Bonanza Productions Inc.","Warner Bros. Television","J.J. Abrams","Steven Lilien","Sarah Jones","Jorge Garcia"]
The source code for splitCSVLine is given in Appendix 1. You can use this method as is or modify it if you wish.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class Movie implements Comparable <Movie> {
private String title;
private int year;
private String director;
private String writer;
private Actor actor1;
private Actor actor2;
private Actor actor3;
private ArrayList<Location> locations;

// Constructor (2 arguments: title and year)
public Movie(String title, int year) throws IllegalArgumentException
{
    if (title.isEmpty())
    {
      throw new IllegalArgumentException ("Empty. No title entered");
    }
    else if ((year>0 && year<1900) || year>2020)
    {
      throw new IllegalArgumentException ("Invalid Year");
    }
    this.title = title;
    this.year = year;
    this.locations = new ArrayList<Location>();
}

// Constructor (7 arguments: title, year, director, writer, actor1, actor2, actor3)
public Movie(String title, int year, String director, String writer, Actor actor1, Actor actor2, Actor actor3) throws IllegalArgumentException
{
    if (title.isEmpty())
    {
      throw new IllegalArgumentException ("Empty. No title entered");
    }
    if (year<1900 || year>2020)
    {
      throw new IllegalArgumentException ("Invalid Year");
    }
    if (director.isEmpty() || director==null)
    {
      throw new IllegalArgumentException ("Error");
    }
    if (writer.isEmpty() || writer==null)
    {
      throw new IllegalArgumentException ("Error");
    }
    if (actor1 == null)
    {
      throw new IllegalArgumentException ("Error");
    }
    this.title = title;
    this.year = year;
    this.director = director;
    this.writer = writer;
    this.actor1 = actor1;
    this.actor2 = actor2;
    this.actor3 = actor3;
    this.locations = new ArrayList<Location>();
}...
$45.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats