LD05: Pure Object Model due Wed 14 Feb 10:00

\begin{purpose}
In this assignment you will:
\begin{itemize}
\item Convert a...
...gram one step closer to a complete OOP
approach.
\end{itemize}
\end{purpose}

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:

  1. Modify the Movie class to adhere to the “pure object model”.
  2. 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.

Preparation for Lab Day

Do these steps:
  1. 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).

  2. 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.

  3. 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?

  4. Commit your changes and then push the changes to bitbucket.

Lab Day

Begin by showing your prelab work (compiler errors!) to the instructor. Then do these steps:

  1. In your workspace make sure you have the most recent code from the base repository and from your homework repository on bitbucket.

  2. 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.

  3. 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.

  4. Compile the driver and verify that you can successfully save. Then document (using JavaDoc) the new method you wrote. Commit your work.

  5. Let's turn our attention to the error found in searchByYear(). Start by uncommenting searchByYear().

  6. 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.

  7. Test the modified searchByYear() method. When it works as desired document your work and commit it.

  8. 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).

  9. Test, document, and commit your new function.

  10. Use any method you like (but keep genre private) to solve the searchByGenre() issue. Test, document, commit.

  11. Show your work to the instructor. Be sure to push your latest commit to your bitbucket repository.

  12. If you finish early begin work on the homework assignment.