| 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:
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.
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:
Several of the methods to be described below generate a set of error conditions identified with the following integer values:
|
Condition |
Integer Value |
|
CORRECT |
0 (No error) |
| INVALID_NAME |
1 |
| INVALID_MOVIE |
2 |
| NONZERO_MOVIES |
3 |
| INVALID_MOVIE_RENTED |
4 |
boolean addMovie(String title, int year, String genre)
The year parameter represents the year the movie was released. The genre parameter refers to the film's genre (e.g., Action, Horror, Romance, etc.). This method will return true if the add operation was completed successfully and false if the movie is already part of the database.
String findMovie(String title)
If the movie is not currently rented, the format of the String to return is:
MovieString ® Title: "title", Year: year, Genre: genre
where title, year, and genre correspond to the movie's title, year and genre. If the movie is currently rented then the format is:
MovieStringRented ® Title: "title", Year: year, Genre: genre (RENTED)
String findMovies(String genre, int year)
If genre is null then the genre is ignored in the search process. If year is -1 the year value is ignored in the search process. The method will return null if no movies satisfy the search criteria. The format of the String to be returned is a sequence of MovieString each on a line by itself. We refer to this list as the MovieList.
boolean addCustomer(String firstName, String lastName,
String address)
The collection of customers is kept sorted by customer name. For example Rose Johnson will appear before Albert Smith. The method will return true if the add operation was successful and false if the customer is already part of the database.
String findCustomer(String firstName, String lastName)
The format of the String to return is one of the following. If the customer has no rented movies the result is:
CustomerString ®
If the customer has rented movies the result is:
CustomerString ®
where the format MovieList was given above.
(Update: (Tue, Nov 9 at 9:20am) Added the line "Movies (rented):" above and updated the following note.)
(Important Note: Due to a bug in our initial implementation, there was an extra space on line 39 of the file "Test2Results.txt", after the line "Movies (rented):". This was fixed on Friday, but people who checked the file out early may still see the space there. If so, you will fail to pass the test. To fix it, simply checkout the latest version of the file "Test2Results.txt" or remove the space yourself.)
int removeCustomer(String firstName, String lastName)
The following error conditions can arise while removing a customer from the database. Each of these conditions will be verified in the order to be presented next. Once an error condition has been recognized, the method will return that condition and ignore the rest. For this method the error conditions are:
If neither of these errors occurs, the value CORRECT should be returned.
int rentAMovie(String firstName, String lastName, String title)
The following error conditions can arise as a result of this operation. These conditions must be tested in the following order. Once an error condition has been recognized, the method will return that condition and ignore the rest.
If none of these errors occurs, the value CORRECT should be returned.
int returnAMovie(String firstName, String lastName, String titleIn)
The following error conditions can arise as a result of this operation. These conditions must be tested in the following order. Once an error condition has been recognized, the method will return that condition and ignore the rest.
If none of these errors occurs, the value CORRECT should be returned.
String allMovies()
The format of the string is defined by MovieList above. A value of null will be returned if there are no movies in the database.
String allCustomers()
The format of the String to be returned is a sequence of CustomerString each on a line by itself. We refer to this list as the CustomerList. A value of null will be returned if there are no customers in the database.
String toString()
This is just the list of movies followed by the
list of customers, that is:
DatabaseString ®
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
Because of the difficulty in grading emailed submissions, we will start deducting points unless you submit via the submit option or the submit server.
(Update: (Sat, Nov 6 at 8:45pm) The following section added.)
The following describes the format of the design.txt file you are expected to provide. Your design file should have three parts:
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.)
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.