| Homework #6 | CMSC 131 |
| Due Tuesday July 19, 3:00 pm | Object-Oriented Programming I |
| Type of Homework: Closed | Summer 2005 |
Objective
This homework will give you practice designing object-based solutions to problems. In addition, it will allow you to practice using arrays of references and javadoc documentation.
Overview
For this homework you will implement a very simple database system for a Cable TV company. Your program will allow the company to keep track of clients and the different TV channels (e.g., TNT, HBO, WETA, etc.) they manage. Unlike previous homework assignments, we will not provide any support infrastructure for this project. You will design and implement all the classes needed to complete the database application. 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: 60% (Implementation), 25% (Design), 10% (Style), 4% (Your JUnit Test), 1% (Time log)
Program Overview
You will write a program that enables a cable company to keep track of the its clients, the channels available to the company and the channels assigns to clients. The program will handle the following tasks:
What you must implement, in a nutshell
You must design and implement a solution to the database application. The design will include documentation for each of the classes that are part of the application and the methods for each class. 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. After completing your design, you will implement it. The number of classes you decide to use is up to you, however, you must follow the 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 application will be represented using two lists:
How you represent these lists is part of your design. You may follow any approach you deem necessary as long as it adheres to the specifications of the homework. Note that you will not use any sorting algorithm in this project. For example, you will keep your client list sorted by inserting elements in the appropriate position in the list. Also, you may not use the ArrayList class for this project. If you use the ArrayList class you will receive not credit for this homework.
Required Classes
The class CableCompany is the class that provides access to the database application. You must defined this class with the methods we have specified below. Aside from this class, it is up to you to define any classes you deem are necessary to complete the project. However, you must defined at least four classes (in addition to the CableCompany) as part of your design.
We expected some specific classes as part of your design, therefore think carefully before you implement any code. As you design your classes make them as general as possible so that they can be recycled by other cable company software engineers. Keep in mind that having a lot of meaningless class doesn't mean you will get a higher grade.
CableCompany
This class represents the database application. Access to the database application is possible through this class. The methods' prototypes and behaviors are defined next. You must not change the following methods' prototypes or add any other public methods. However, feel free to add any private methods and instance variables you understand are necessary.
Methods (all are public methods)
public boolean addChannel(String name, int number, double cost);
The name parameter represents the channel's name. The number represents the channel number assigned to the channel and cost represents the monthly cost for receiving the channel. This method will return true if the add operation was completed successfully and false otherwise. Keep in mind that a channel is uniquely identified by its name.
public String findChannel(String name);
The format of the String to return is:
ChannelString ® "Channel Name: " name "|Number: "number"|Cost: " cost
where name, number, and cost correspond to the channel's name, number and cost, respectively.
public boolean removeChannel(String name);
public String getAllChannels();
The format of the String to be returned is a sequence of ChannelString each on a line by itself. We refer to this list as the ChannelStringList.
public boolean addClient(String name, String address);
The collection of clients is kept sorted by client name. Names will be specified by providing the last name first followed by the first name (with a comma in between). For example, Rose Johnson will be specified as "Johnson,Rose". The method will return true if the add operation was successful and false otherwise (e.g., if the client is already part of the database). You can assume users of the CableCompany class will provide names with the expected format (e.g., no spaces before the first and last character of the name).
public String findClient(String name);
The format of the String to return is one of the following:
ClientString®
"Name: "name", Address: "address
"Channel List:"
ChannelStringList
OR
ClientString®
"Name: "name", Address: "address
"Channel List: None"
public boolean removeClient(String name);
Returns true if the remove operation was successful and false otherwise (e.g., the name is not found).
public String getAllClients();
The format of the String to be returned is a sequence of ClientString each on a line by itself.
public boolean assignChannelToClient(String clientName, String channelName);
The method returns true if the assignment is successful and false otherwise (e.g., the customer doesn't exist or the channel is not valid).
public String computeClientsBill(String clientName);
Requirements/Assumptions
Complete the design.txt file you will find in the code description.
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 directory, within its bin directory. For example, on a typical Windows machine, this might be:
C:\Program Files\Java\jdk1.5.0_03\bin\javadoc.exe
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 javadoc files 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. If you see some directories with the "doc" prefix in your project workspace then you have not specified an appropriate "Destination".
JUnit Tests
We have provided a JUnit test you can use to verify the correctness of your code. However, you must provide your own JUnit module that shows the set of tests you used to verify your implementation is correct. Please name your JUnit test module JUnitMyTests.java.
At the end of this page you will find a class ExampleDriver.java and the output that it produces. Access to the database application is through the CompanyCable class you will implement. The class ExampleDriver.java can be found in the code distribution.
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. Remember to define a main method in the Challenge class that allow us to run your program.
The challenge problem consists of defining a GUI for the database software application. The GUI should allow a user to complete all the tasks associated with the CableCompany class. Feel free to define your interface as you understand is best. Keep in mind that a GUI based on JOptionPane is considered a valid GUI although you may not receive the maximum number of gold stars.
Submission
Submit your project using the submit project option associated with Eclipse. Make sure that the submit server generates the expected results.
ExampleDriver.java
public class ExampleDriver {
public static void main(String[] args) {
System.out.println("*****Loading some channels*****");
CableCompany cableCompany = new CableCompany();
loadChannels(cableCompany);
System.out.println(cableCompany.getAllChannels());
System.out.println("*****Loading some clients*****");
loadClients(cableCompany);
System.out.println(cableCompany.getAllClients());
System.out.println("*****Looking up some information*****");
System.out.println("*****Looking information about a channel*****");
String channelInfo = cableCompany.findChannel("ABD");
if (channelInfo != null) {
System.out.println(channelInfo);
}
System.out.println("*****Looking information about a client*****");
String clientInfo = cableCompany.findClient("Smith,Robert");
if (clientInfo != null) {
System.out.println(clientInfo);
}
System.out.println("*****Assigning channels to clients*****");
cableCompany.assignChannelToClient("Smith,Robert", "ABD");
cableCompany.assignChannelToClient("Smith,Robert", "NBO");
cableCompany.assignChannelToClient("Smith,Robert", "CBC");
cableCompany.assignChannelToClient("Anderson,Paola", "NBO");
System.out.println("*****After assigning ABD, NBO and CBC to Smith,Robert*****");
System.out.println(cableCompany.findClient("Smith,Robert"));
System.out.println("*****After assigning NBO to Anderson,Paola*****");
System.out.println(cableCompany.findClient("Anderson,Paola"));
System.out.println("*****Computing client's bill*****");
System.out.println("Bill: " + cableCompany.computeClientsBill("Smith,Robert"));
}
private static void loadChannels(CableCompany cableCompany) {
cableCompany.addChannel("NBO", 304, 15.00);
cableCompany.addChannel("ABD", 7, 3.99);
cableCompany.addChannel("CBC", 9, 4.0);
}
private static void loadClients(CableCompany database) {
database.addClient("Smith,Robert", "4100 Berwyn Road Bethesda MD");
database.addClient("Johnson,Mary","8000 Silver Lane Colesville MD" );
database.addClient("Anderson,Paola","14 St NW Washington DC");
}
}
Driver's Output
*****Loading some channels***** Channel Name: NBO|Number: 304|Cost: 15.0 Channel Name: ABD|Number: 7|Cost: 3.99 Channel Name: CBC|Number: 9|Cost: 4.0 *****Loading some clients***** Name: Anderson,Paola, Address: 14 St NW Washington DC Channel List: None Name: Johnson,Mary, Address: 8000 Silver Lane Colesville MD Channel List: None Name: Smith,Robert, Address: 4100 Berwyn Road Bethesda MD Channel List: None *****Looking up some information***** *****Looking information about a channel***** Channel Name: ABD|Number: 7|Cost: 3.99 *****Looking information about a client***** Name: Smith,Robert, Address: 4100 Berwyn Road Bethesda MD Channel List: None *****Assigning channels to clients***** *****After assigning ABD, NBO and CBC to Smith,Robert***** Name: Smith,Robert, Address: 4100 Berwyn Road Bethesda MD Channel List: Channel Name: ABD|Number: 7|Cost: 3.99 Channel Name: NBO|Number: 304|Cost: 15.0 Channel Name: CBC|Number: 9|Cost: 4.0 *****After assigning NBO to Anderson,Paola***** Name: Anderson,Paola, Address: 14 St NW Washington DC Channel List: Channel Name: NBO|Number: 304|Cost: 15.0 *****Computing client's bill***** Bill: $22.99