CS 261 Homework 1 - Movie Library
Due Thu Sep 11 at 11:59pm
Overview
This assignment will help you refresh your Java basics, and give you a chance to practice working with the Eclipse IDE. Your task is to write a set of Java classes that together manage a simple movie library, such as you might use to keep track of a personal video collection. This program will allow users to load a list of movies from a file, search through the list, add or remove items from the list, and then save the list back to a file. Users will interact with the system through the command-line, using a menu such as the one below:
Welcome to the movie library. Select an option: 1. List movies in library 2. Look up a movie by title 3. Look up movies by actor 4. Look up highest rated film 5. Add a movie to the library 6. Remove a movie from the library 7. Load a library from a file 8. Save movie library to a file 9. Exit system >
This assignment should be completed individually.
Objectives
- To review some topics (ArrayLists, loops, the Scanner, etc) from CS 161
- To practice creating and using Abstract Data Types in Java
- To practice writing simple search algorithms
- To practice reading and producing code documentation
- To practice with the Eclipse IDE
Necessary Files
You will need to download the cs261-hwk1.zip file.
This zip file contains a MovieLibraryLoader.java
utility class that will let you load and save your library to a file by using the provided static methods. You should import this class into your Eclipse project (in the same manner you imported classes in
Lab A).
Note that you will need a new Eclipse project for this assignment--select "New > Java Project" from the File menu to create a new project (e.g., "Hwk1").
The zip file also contains movies.txt
, a small example movie library you can use for testing. You should also import this file into Eclipse. However, this file is not source code--it should not go in the src
folder! Instead, make sure the file is in the "top-level" directory of your project: directly under the "Hwk1" folder (for example).
- While you are not required to import this file, it will make writing and test your program more pleasant.
Finally, the zip file also contains a README.txt for this assignment, which you will need to fill out with details about your assignment and turn in along with your code. I recommend you import this into your Eclipse project as well, so you don't forget about it!
Assignment Details
I recommend you read through all of these instructions carefully before you begin! There are a couple of different pieces to this assignment you will need to complete.
Think through how you will organize and complete each method before you begin. You should outline your code, writing the method signatures and JavaDocs before you fill in the algorithm details. This will help you figure out what methods go where and call what. If you get stuck, come and see me!
This isn't a small amount of work. GET STARTED EARLY!
-
You will need to implement a
Movie
class that represents a film in the library. This will be a simple ADT (abstract data type) that encapsulates information about a particular film.Your Movie class should support the following public interface:
Movie(String title, int year, String director, ArrayList<String> actors, double rating) //a constructor for the movie String getTitle() //gets the title of the film int getYear() //gets the year the film was released String getDirector() //gets the director of the film String[] getActors() //gets a list of actors in the film double getRating() //gets a rating (out of 10) for the film
This interface is required by the provided
MovieLibraryLoader
class.- Be sure and use good information hiding practices. Keep your instance variables private, and don't hand away access if you can avoid it!
-
You are welcome to create other helper methods as well. For example, you will likely get good milage out of having a
toString()
method that you can use to easily print out the details of the film.
-
Next, you will need to implement a
MovieLibrary
ADT. This class will represent your movie library (your list of movies). It should be a relatively simple class to create. It will need to support the following functions:-
Get a list of the titles of all the movies in the library.
- Be careful about information hiding; don't give away full access to your instance variables!
-
Get the details of the movie with a given title.
- You will need to search through the list of movies to find the one with the correct title. You can use a basic linear search--simply loop through the movies and check if each one has the title you're interested in. Remember to compare Strings using
.equals()
not==
- Consider how to delegate functionality in your program; is it more appropriate for the the
MovieLibrary
class to figure out how to present the details of a film once you've found it, or for theMovie
class?
- You will need to search through the list of movies to find the one with the correct title. You can use a basic linear search--simply loop through the movies and check if each one has the title you're interested in. Remember to compare Strings using
-
Get a list of movies that contain a given actor.
- You will again need to search through the list of movies. But for each movie, you'll also need to search through the list of actors. If that list contains the actor you're looking for, you'll need to add the current movie to a list of "movies with that actor" that you can return.
- In the sample library file, two movies star a young Harrison Ford. This may help with testing.
-
Get the movie with the highest rating.
-
This will involve one more more search. In this case, you'll need to do a king of the hill search. This is a search you use to find the "-est" (biggest, smallest, etc) item in the list. The basic algorithm is based on the children's game "king of the hill":
Make the first item the "king" for each other item: if that item beats the current king that item becomes the king return whoever the king is
This is a common searching pattern that you should have in your toolbelt!
-
This will involve one more more search. In this case, you'll need to do a king of the hill search. This is a search you use to find the "-est" (biggest, smallest, etc) item in the list. The basic algorithm is based on the children's game "king of the hill":
-
Add a new movie to the library.
- You should NOT be able to add a duplicate film--that is, a film with the same title and year. Make sure you search for duplicates before adding a film to your library
-
Remove a movie from the library.
- Remember, a movie is designated by its title AND year, not just it's title!
-
Load a list of movies from a file.
-
You can use the provided static
MovieLibraryLoader.loadMoviesFromFile()
method to do this easily. Note that this method takes a filename as a paramer. This is the relative path to the file--that is, how to find the file from the top-level directory of the Eclipse project. So if you put themovies.txt
file in that top-level directory, you can simply callMovieLibraryLoader.loadMoviesFromFile("movies.txt")
, put if you put that file in a folder called "libraries" inside the project directory, you'd need to callMovieLibraryLoader.loadMoviesFromFile("libraries/movies.txt")
. Check the included JavaDoc for more details about using the method. -
Important! Your final submission should pass this method a
null
parameter so that it prompts the user via a GUI. Providing a hard-coded filename is useful for testing, but not appropriate for submission.
-
You can use the provided static
-
Save a list of movies to a file.
-
You can use the provided static
MovieLibraryLoader.saveMoviesToFile()
method to do this easily. This method takes a filename as a parameter just like the loading method does.
-
You can use the provided static
I have left the specifics of the method signatures purposefully vague. You should be able to design your own methods to provide the required functionality!
- This may seem like a lot of work, but each method is actually very simple (the kind of thing you should have written in 161).
- Be sure to test and check each new method as you add it to make sure it works!
-
Get a list of the titles of all the movies in the library.
-
Finally, you will also need to implement a
MovieLibraryManager
class. This class will act as an "user interface" for theMovieLibrary
. It should include methods that prompt the user for actions to take (e.g., what movies to search for), and then calls the appropriate methods on theMovieLibrary
.- Look at the sample menu at the top of the assignment for a list of options the user should be able to perform.
-
I recommend you make a separate helper method to handle each action; this will make it easy to organize and test your code. Note that each helper method may prompt the user for further information (e.g., for which actor to search for).
- Remember you can get input from the user through the Scanner class (described on page 662--64 in the book). I recommend making 1 Scanner for the entire class to use as an instance variable so you don't need to keep reallocating memory.
-
Then include a
mainMenu()
method that displays the main menu, lets the user enter an option (e.g., "4") and then calls the appropriate helper method. You should use a loop to allow the user to select an option multiple times. If the user selects "exit", then leave the loop!- Important! Please make sure your numbered menu options match the example at the top of the assignment, to ease your professor's job in grading!
- Another Important Point! This class is your "user interaction class". That means that all user interaction--all print outs, all Scanner.nextLine() requests--should go in this class. It is good program design to keep your interaction (the "view") separate from the logic of your program (the "model"); this makes it possible to create a new user interface such as a GUI without needing to redo your program's logic.
- Similarly, be careful to keep program logic in an appropriate class: what work should the MovieLibrary do, and what work should the MovieLibraryManager do? If you're unsure, feel free to check in with me or ask on Piazza.
-
This class will also have your
main()
method. Note that a goodmain()
method is lean--it doesn't contain a lot of code, instead calling a helper method to get started.- A cleaner way would be to create a separate
MovieLibraryManagerDriver
class to test things, but that can be a bit redundant.
- A cleaner way would be to create a separate
-
Be sure that all your code is fully documented. That means you should have:
- A class comment on every class, which includes your name in the
@author
tag -
A complete JavaDoc comment (with
@param
and@return
tags) on every method.Eclipse makes these easy to include.- Pro Tip! Write out the JavaDoc before you fill in the method! This will help you think through the point of the method (which helps to organize code), as well as to keep methods straight in your head.
- Sufficient inline comments to explain your algorithms/code logic to the reader (i.e., the professor)
Remember that your comments should explain the why of the code, not the what. Comments explain why you include a line of code, not just what it does.
- A class comment on every class, which includes your name in the
- Last but not least, be sure to complete the README.txt that you found in the Hwk1.zip file, and upload it along with your code!
Submitting
BEFORE YOU SUBMIT: make sure your code is fully documented and functional! If your code doesn't run, I can't give you credit! Your name should be in the class comment at the top of each class.
Submit your program to the Hwk1 submission folder on vhedwig, following the instructions detailed in Lab A. Make sure you upload your work to the correct folder!.
You should upload your entire src folder with all your classes, as well as your movies.txt
if you added any films.
Be sure to complete the provided README.txt file with details about your program.
The homework is due at midnight on Thu Sep 11.
Extensions
There are lots of extensions you could add to this assignment. You could add the ability to modify movies, to add or remove actors, to sort films by some criteria (or multiple criteria), or to track other information such as genre(s), the running time, or box office receipts.
Grading
This assignment will be graded out of 30 points:
- Functionality (21pt)
- [3pt] Includes a Movie ADT that fulfills the required public interface
- [1pt] The Movie ADT uses good encapsulation practice
- [1pt] MovieLibrary class lists the titles of movies (option 1).
- [2pt] MovieLibrary class gives details of a movie with a given title (option 2).
- [2pt] MovieLibrary class lists all movies starring a given actor (option 3).
- [2pt] MovieLibrary class reports the movie with highest rating (option 4).
- [2pt] MovieLibrary class allows the user to add a new movie to the library (option 5). Duplicates are disallowed.
- [1pt] MovieLibrary class allows the user to remove a movie from the library (option 6).
- [2pt] MovieLibrary class allows the user to load from and save the movies to a file (option 7&8) The user is prompted for the file via a GUI.
- [2pt] MovieLibraryManager allows the user to choose each of the 8 options. Options can be chosen more than once.
- [1pt] MovieLibraryManager prompts the user for extra information (e.g., actor names) when necessary
- [1pt] MovieLibraryManager options are in the specified order.
- [1pt] MovieLibraryManager allows the user to exit the system.
- Style (5pt)
- [3pt] Classes show good division of functionality (cohesion): user interaction is in the MovieLibraryManager, movie list interaction is in the MovieLibrary, and movie specification is in the Movie class.
- [1pt] Your code uses descripive and properly formatted class, variable, and method names
- [1pt] Your code uses appropriate data hiding with public and private methods and variables.
- Documentation (4pt)
- [1pt] Each class has a class comment with your name in the
@author
field - [2pt] All methods include JavaDoc comments with appropriate JavaDoc tags (
@param
and@return
). - [1pt] The README is completed.