We have been systematically moving our movie database program from a structured
design to an object-oriented design. At this point there are two main changes
we need to make to complete this metamorphosis:
- Modify the Movie class to adhere to the “pure object model”.
- Create an object-oriented user interface for the program.
We will focus on the first step in this week's lab day and the second step
in the homework assignment.
Do these steps:
- In your workspace, make sure you have the latest homework files from
the base repository. If necessary, also get the latest files from your
bitbucket repository. This will create a hw05 directory. Copy all
the files from hw04 into this new directory (except for the files
related to the Clicker class).
- To convert the Movie class to adhere to the pure object model
is simple: modify it so that its attributes are private. Go ahead and
do that now.
- Unfortunately, making that change will cause some of the code in your
MovieContainer class to break. You don't need to fix those errors
for this prelab assignment: We will devote our time in lab day to
experimenting with ways to deal with the broken code. For now, try to
compile your Driver and make note of the resulting errors. Do you
understand why those lines no longer compile?
- Commit your changes and then push the changes to bitbucket.
Begin by showing your prelab work (compiler errors!) to the instructor. Then do
these steps:
- In your workspace make sure you have the most recent code from the base
repository and from your homework repository on bitbucket.
- I am expecting that there are four places your program isn't compiling:
- when saving the array to disk
- when searching by title
- when searching by genre
- when searching by year
Let's consider some different approaches to solving these issues. Begin by
commenting out your searchByxyz methods and focus only on the
error in the save() method.
- Since the MovieContainer class is not allowed to see the
private attributes of the Movie class we will ask the Movie
class to take on extra responsibilities. Add a new method to the Movie
class named writeToFile that accepts a PrintStream (or
PrintWriter) object as a parameter. The method should write the class
attributes to the provided PrintStream object with one attribute per
line. Then in the save() method remove the println and replace
it with a call to the new writeToFile() method.
- Compile the driver and verify that you can successfully save. Then
document (using JavaDoc) the new method you wrote. Commit your work.
- Let's turn our attention to the error found in searchByYear().
Start by uncommenting searchByYear().
- Another way to handle sharing is to provide a getter for an attribute.
Do this by creating in Movie a getYear() method that will
return the year value. Then modify the code int searchByYear to
call the getter in place of the attribute.
- Test the modified searchByYear() method. When it works as
desired document your work and commit it.
- Let's handle the searchByTitle() method by adding a method
to the Movie class called matchesTitle() that accepts
the search string as a parameter and returns true if that search
string is a case-insensitive partial match (false otherwise).
- Test, document, and commit your new function.
- Use any method you like (but keep genre private) to solve the
searchByGenre() issue. Test, document, commit.
- Show your work to the instructor. Be sure to push your latest
commit to your bitbucket repository.
- If you finish early begin work on the homework assignment.