Lab 7: Passing Objects Between Objects

Copyright RIT 2004
$Id: writeup.xml,v 1.8 2009/10/19 13:12:30 vcss231 Exp vcss231 $


Goal

This lab will introduce you to the idea of using a class as a complex data type in order to return several related values from a method.

This lab will also give you practice writing a class - including a unit test - from a javadoc.

Often an object will be created in one module and needed in another. You will also practice passing objects between other objects in this lab.


Team Setup

You are to work on this lab completely on your own.

Overview

Objectives

Pre - Lab Work

  1. Review your course notes, review Chapter 7 in Liang.

In-Lab Activities

Activity #1 : Implement and test the Customer class

Using the Customer javadoc, implement the complete class. Start with the stubs, then add the implementations for each method and both constructors. Compiling after each step may make it easier for you to find your syntax errors.

When you have provided an implementation for each method and both constructors, write a unit test. When implementing new classes, a standard practice is to include the unit test in the same module - include a main method right in your Customer.java class. Including the unit test in the class itself offers several advantages - it documents the tests that were performed, and since the unit test is a part of the code, it's easy to rerun or expand the tests. If the code is modified, you can easily add additional tests for the new code, then run a complete regression test to ensure new defects were not introduced. Remember that the main method only executes if you run "java Customer"; someone using your class to only create Customer objects would not need to know (or care!) that the unit test is still in your code.

Before you submit, check the details. How does your code look? Does it follow the coding standard? Does each method and constructor include a header?

Here's a good check -- create the javadoc. After compiling your program, run the command "javadoc Customer.java". This will build a file named "Customer.html". Load "Customer.html" into your browser; it should look just the one we provided.

You will be graded on the correctness of your implementation AND the quality of your test program.

How To Submit

When you are convinced that your program works correctly, submit it using the following command:


	try grd-231 lab7-1 Customer.java 
        

Activity #2 : Use your Customer.java class to create and manipulate a Customer database

Download and unpack the jar file here (/~vcss231/pub/lab07/Binaries/lab7.jar) . In the jar file is a class file "CustomerDatabase.class" and the partial code for "CustomerDatabaseManager.java". The jar file also contains a sample data file; use this file along with other tests you develop to verify that your code works correctly. The CustomerDatabase.class file is a complete and correct working class you may use to create and manipulate a database of Customer objects. Review the javadoc for the CustomerDatabase class to become familiar with the methods you can call to build and manipulate the customer database.

The "CustomerDatabaseManager.java" file is a partial implementation of a menu-driven program that will allow you to add, query and update Customer objects in the database. Your job is to complete the code in this class. There are comments throughout to guide you in what you must do.

Keeping with good programming practice, the main method contains a limited amount of code. It has been divided into several methods which you should call to perform various functions.

Complete the code as instructed in the "CustomerDatabaseManager.java" file and as shown on the CustomerDatabaseManager. Run your solution using various test scenarios. Refer to your notes from lab 4 where you designed test cases.

Read the CustomerDatabase javadoc carefully. Note that when customers are added to the database, they are assigned an ID. ID numbers start at 1 and increment by one for each new customer. Customer IDs are unique for each customer.

Also, please note that we provided the "menu" prompts in the "CustomerDatabaseManager.java" program. Do not change or add additional prompts. As always, remember that you may never change the specifications!

How To Submit

When you are sure your program produces the correct results, submit it using the following command:

try grd-231 lab7-2 CustomerDatabaseManager.java
	


Grade Computation

Grade Breakdown: