Homework #6 CMSC 131
Due Nov 11, 6:00 pm Object-Oriented Programming I
Type of Homework: Closed Fall 2004

(Most recent update: Wed, Nov 10 at 8:20am. Look for red "Update:" tags.)

Objective

This homework will give you practice designing object-based solutions to problems. In addition, it will allow you to practice arrays of references and javadoc documentation.

Overview

For this homework you will implement a program that keeps track of customers and movies in a video store. Your program will allow employees to add customers to the database, to add movies, to change the status of a movie (from available to rented), etc. Different from other homeworks, we will not provide any support infrastructure for this project. You will design and implement all the classes needed to complete the video store application. More details about the program are provided in the Specifications section. You may want to take a look at the Sample Run section before you read the detailed description.

This homework will be graded as follows:

Specifications

Program Tasks Overview

You will write a program that enables an video store employee to complete the following tasks:

Assumptions

What you must implement, in a nutshell

You must design a solution to the video store application. The design will describe each of the classes that are part of the application and which methods each one has. We have intentionally only provided the most critical classes. You are expected to design your own classes for representing the basic entities that the program manipulates. You will document your design in the design.txt file, which is part of the code distribution. See the section on design documentation below. After completing your design, you will implement it. The number of classes you decide to use is up to you, however you have to follow a set of restrictions specified below.

Code Distribution

Before you read these specifications, you should access the files associated with this homework by checking out the project named p6. The code distribution provides you with the following:

Database Representation

The database of the video store application will be represented using two sorted lists:

How you represent these lists is part of your design. You can follow any approach you understand is necessary as long as it adheres to the specifications of the homework. Notice that you will not use any sorting algorithm in this project. You will keep your lists sorted by inserting elements in the appropriate position in the list.

Required Classes

You must implement and use the following classes:

Customer

This class represents a customer. A customer is identified by a name (firstname and lastname), address, and an array of movies that the customer currently has rented. As long as you defined an array of movies as part of the instance variables of this class you will be okay. We leave it up to you to define the methods you will need.

(Update: (Mon, Nov 8, 11:00pm) Added "currently" above. Throughout, when we talk about the videos that a customer has rented, we mean "currently" rented.)

VideoStore

This class represents the video store application. Actually, this is the class we will use to test your program. Access to the video store application is through this class. The methods' prototypes and behaviors are defined next:

Additional Classes

As part of your design you will need to define classes in addition to the ones described above. Think carefully about the classes you will need. A good design can simplify dramatically the amount of time you will spend implementing your design. We recommend you implement a class called Name which represents a customer's name. It will have, among other methods, a method that will compare two names so you can insert names in sorted order.

Requirements

(Update: (Sat, Nov 6 at 8:45pm) The following section added.)

Design Documentation

The following describes the format of the design.txt file you are expected to provide. Your design file should have three parts:

Sample Run

At the end of this page you will find a class Example.java and the output that it produces. Access to the application is through the VideoStore class, which you will implement. The class Example.java can be found in the code distribution.

(Update: (Wed, Nov 10 at 8:30am) The following section added.)

JavaDoc

As mentioned above, you are to provide javadoc documentation for one of your classes, and will indicate which class in your design.txt file.

You should not provide the html files generated by the javadoc utility with your submission. We will generate the files ourselves.

To run Javadoc from Eclipse, select the file, right click, and select "Export → Javadoc". The first time you attempt to do this, Eclipse will ask you to specify the location of your javadoc executable. This file will be located in your Java j2sdk directory, within its bin directory. For example, on a typical Windows machine, this might be

On a typical Unix/MacOS machine the file will likely just be called "javadoc", and again will be in the Java sdk directory.

Remember to store the file outside your workspace. When exporting javadoc it will ask you for the "Destination" to store the javadoc documentation files. Please specify a directory that is outside of your Eclipse Workspace, so it does not affect your submission.


Challenge Problem

Remember that you are not required to implement the following problem. Please visit the course web page for information regarding challenge problems. IMPORTANT: If you decide to complete the challenge problem you must provide its implementation in the file called Challenge.java.

The challenge problem consists of defining a GUI for the video store application. The GUI should allow a user to complete all the tasks associated with the VideoStore class.  Feel free to define your interface as you understand is best, providing any error messages you understand are appropriate.   Remember to define a main method in the Challenge class that allow us to run your program.


Submission

Submit your project using the submit project option associated with Eclipse. Remember to complete your time log before submitting your homework.


Example.java

(This is provided in the code distribution.)

public class Example {
    public static void loadMovie(VideoStore videoStore,
            			   		 String title,
            			   		 int year,
            			   		 String genre) {
        System.out.println("Adding movie: \"" + title + "\"");
        videoStore.addMovie(title, year, genre);
        System.out.println("***VideoStore Database***");  
        System.out.println(videoStore);
        System.out.println();
    }
 
    public static void loadCustomer(VideoStore videoStore,
			   						String firstname,
			   						String lastname,
			   						String address) {
        System.out.println("Adding customer: " + firstname + " " + lastname);
        videoStore.addCustomer(firstname, lastname, address);
        System.out.println("***VideoStore Database***");  
        System.out.println(videoStore);
        System.out.println();
    }
    
    public static void main(String[] args) {        
        String results = "", info;
        
        VideoStore videoStore = new VideoStore();
        
        /* Adding some movies and printing the database status after each add */
        loadMovie(videoStore, "Eclipse", 2004, "Horror");
        loadMovie(videoStore, "Compilation in Outer Space", 1976, "Action");
        loadMovie(videoStore, "A Simple Homework", 1990, "Comedy");
        
        /* Adding some customers and printing the database status after each add */
        loadCustomer(videoStore, "John", "Smith", "8th Street Bethesda CA");
        loadCustomer(videoStore, "Rose", "Peterson", "101 Road RiverTown CA");
        System.out.println("***All movies***\n" + videoStore.allMovies() + "\n");
        System.out.println("***All customers***\n" + videoStore.allCustomers());
        
        System.out.println("\n***Looking for Horror movies***");
        if ((info = videoStore.findMovies("Horror", -1)) != null)
            System.out.println(info);
        
        System.out.println("\n***Looking for movies released on or after 1989");
        if ((info = videoStore.findMovies(null, 1989)) != null)
            System.out.println(info);    
        
        System.out.println("\n***John Smith is renting the movie \"Eclipse\"");
        if (videoStore.rentAMovie("John", "Smith", "Eclipse") == 0) 
            System.out.println(videoStore);
     
        System.out.println("\n***Looking for the movie \"Eclipse\"");
        if ((info = videoStore.findMovie("Eclipse"))!= null)
            System.out.println(info);
          
        System.out.println("\n***John Smith is returning the movie \"Eclipse\"");
        if (videoStore.returnAMovie("John", "Smith", "Eclipse") == 0)
            System.out.println(videoStore);
    }
}

Output of Example.java

  Adding movie: "Eclipse"
  ***VideoStore Database***
  Title: "Eclipse", Year: 2004, Genre: Horror
  
  Adding movie: "Compilation in Outer Space"
  ***VideoStore Database***
  Title: "Compilation in Outer Space", Year: 1976, Genre: Action
  Title: "Eclipse", Year: 2004, Genre: Horror
  
  Adding movie: "A Simple Homework"
  ***VideoStore Database***
  Title: "A Simple Homework", Year: 1990, Genre: Comedy
  Title: "Compilation in Outer Space", Year: 1976, Genre: Action
  Title: "Eclipse", Year: 2004, Genre: Horror
  
  Adding customer: John Smith
  ***VideoStore Database***
  Title: "A Simple Homework", Year: 1990, Genre: Comedy
  Title: "Compilation in Outer Space", Year: 1976, Genre: Action
  Title: "Eclipse", Year: 2004, Genre: Horror
  Name: John Smith
  Address: 8th Street Bethesda CA
  No movies rented.
  
  Adding customer: Rose Peterson
  ***VideoStore Database***
  Title: "A Simple Homework", Year: 1990, Genre: Comedy
  Title: "Compilation in Outer Space", Year: 1976, Genre: Action
  Title: "Eclipse", Year: 2004, Genre: Horror
  Name: Rose Peterson
  Address: 101 Road RiverTown CA
  No movies rented.
  Name: John Smith
  Address: 8th Street Bethesda CA
  No movies rented.
  
  ***All movies***
  Title: "A Simple Homework", Year: 1990, Genre: Comedy
  Title: "Compilation in Outer Space", Year: 1976, Genre: Action
  Title: "Eclipse", Year: 2004, Genre: Horror
  
  ***All customers***
  Name: Rose Peterson
  Address: 101 Road RiverTown CA
  No movies rented.
  Name: John Smith
  Address: 8th Street Bethesda CA
  No movies rented.
  
  ***Looking for Horror movies***
  Title: "Eclipse", Year: 2004, Genre: Horror
  
  ***Looking for movies released on or after 1989
  Title: "A Simple Homework", Year: 1990, Genre: Comedy
  Title: "Eclipse", Year: 2004, Genre: Horror
  
  ***John Smith is renting the movie "Eclipse"
  Title: "A Simple Homework", Year: 1990, Genre: Comedy
  Title: "Compilation in Outer Space", Year: 1976, Genre: Action
  Title: "Eclipse", Year: 2004, Genre: Horror
  Name: Rose Peterson
  Address: 101 Road RiverTown CA
  No movies rented.
  Name: John Smith
  Address: 8th Street Bethesda CA
  Movies (rented): 
  Title: "Eclipse", Year: 2004, Genre: Horror
  
  ***Looking for the movie "Eclipse"
  Title: "Eclipse", Year: 2004, Genre: Horror (RENTED)
  
  ***John Smith is returning the movie "Eclipse"
  Title: "A Simple Homework", Year: 1990, Genre: Comedy
  Title: "Compilation in Outer Space", Year: 1976, Genre: Action
  Title: "Eclipse", Year: 2004, Genre: Horror
  Name: Rose Peterson
  Address: 101 Road RiverTown CA
  No movies rented.
  Name: John Smith
  Address: 8th Street Bethesda CA
  No movies rented.