LD04: Intro to OOP due Wed 07 Feb 10:00

\begin{purpose}
In this assignment you will:
\begin{itemize}
\item Create a ...
...tinue working with {\tt git} from the command-line
\end{itemize}
\end{purpose}

Preparation for Lab Day

In class we have discussed the “pure object model” and how it pertains to object-oriented design. We also looked at a physcial device that might be called a counter or a clicker. The device we saw has a display that shows the current value of the counter, a button, which when clicked, increments the counter, and a mechanism for reseting the counter to zero.

IMPORTANT: The class you are creating for prelab is simply for the purpose of providing practice in thinking in an object-oriented way and in creating a class accordingly. We will not use this counter in the remainder of lab day.

Do these steps:

  1. In your workspace, make sure you have the latest homework files from the base repository (git pull origin). This will create a hw04 directory that contains a couple of starter file. If necessary, the also get the latest files from your bitbucket repository (git pull mine).

  2. On a piece of paper draw a UML diagram that shows how you would represent the device described above as a class that adheres to the pure object model.

  3. In the provided hw04 directory modify the Clicker.java file to match the functionality you defined in your UML diagram.

  4. In the driver add statements that fully demonstrate the code in your Clicker class. In your demo you should have more than one instance of the Clicker class.

  5. If you have not done so already go ahead and add a toString() method to your Clicker class.

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

Lab Day

Begin by showing your prelab work 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. Copy ArrayofObjectsMovies.java (or whatever you called the main program), Movie.java, and Driver.java from hw03 to hw04. Change to the hw04 directory and do your remaining work in it.

  3. The code in ArrayofObjectsMovies.java (or whatever you called the main program) will essentially be split into to parts. Rather than retyping it all we'll just make two copies of it. So copy it to MovieContainer.java. Then rename ArrayofObjectMovies.java to MovieUI.java. We are making two copies of this because it will be convenient later. Your hw04 directory should have four new files now. Go ahead and commit that change.

  4. The remainder of the instructions will involve modifying MovieContainer.java and Driver.java to test it. The ultimate goal for MovieContainer.java is for it to provide a container for movies that does not require interaction from the user. One of the things we want to be able to do with a movie is add it to the container. It will work very much like our original enterMovie() method except that rather than have the user enter values to be added, we accept them as parameters (without involving the user). The UML diagram for our MovieContainer looks like this:

    MovieContainer
    – Movie [] movies array of movie objects
    – int numMovies number of movies in array
    – String dataFile name of data file
    + MovieContainer(dataFile) constructor reads data from file into container
    + insert(title,genre,year) add new entry to container
    + remove(index) remove entry from container (at index)
    + save() save container contents to data file
    + display() display all entries in container
    + size() return number of entries in container
    + searchByTitle(title) display all entries that match title
    + searchByGenre(genre) display all entries that match genre
    + searchByYear(year) display all entries that match year

  5. Modify MovieContainer.java to rename the class, remove the menuChoice() method, and add the attributes named in the UML diagram. Remember, attributes should be private. You can keep the constant MAXMOVIES. Comment out all methods except for displayAll().

  6. Start by modifying the displayAll() method to match the display() method in the UML diagram. These are the changes you will need to make to convert the original displayAll() method to the new approach:
    • rename the method to display()
    • remove the keyword static
    • remove the parameters
    • modify the code so that the variable n is replaced with numMovies.

    Work with it until it compiles.

  7. In Driver.java remove the existing code and replace it with a statement that creates a new instance of the MovieContainer class. Then call the newly created display() method. Of course, there are no movies in the container so you will only see a header.

  8. Once the driver compiles and runs, displaying the header, modify the documentation in both programs to match the changes you made. Then commit your work.

  9. Now turn your focus into replacing the old enterMovie() method with the insert() method described in the UML diagram. You will need to adjust the parameter list and remove the statements that get values from the user (because the values are being provided as parameters). Work with it until it compiles and you think it should work.

  10. Turn your attention to the driver. Call the new insert() method three times in the driver and then call display(). When this code is working, adjust your documentation to match the changes.

  11. Show your work to the instructor. Then commit your changes and push them to your bitbucket repository.

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