Assignment

A2: Implementing Classes and Fundamental Data Types

Due Date Wednesday, July 6, 2005 at 4:00 pm (CSL Time)
Last Mod Date
Links
Announcements
06/28/2005 Released

Objectives

Description

A small media store founded in 1920 is having a sale. In the past they used a calculator to compute the total price for a customers purchase. The unbelievably low prices at the sale have caused a lot of customers to flock to the store. Fortunately/unfortunately they will need to replace the calculator with a sophisticated Java program if they want to tend to all their customers. The customers are usually undecided and keep adding and removing items even after they have reached the checkout counter. You are now employed to work on the back end of the application.

The store only carries DVDs, books, and VHS tapes.

You are required to write a MediaStoreBiller class that contains all the backend code. You will also be required to write a test class, MediaStoreBillerTester, that contains a main method and tests the methods of your MediaStoreBiller class to verify that they work correctly. To demonstrate your understanding of this step, you must submit a text file expected.out that contains the expected results of your tests. Finally, you must answer some questions relating to the assignment.

MediaStoreBiller Specification

Instance Fields

You will need three instance fields to store the number of DVDs, number of books, and number of VHS tapes. Each will store the number of media of the given type on the current bill.

Class Constants

Each DVD costs $25.00, each book costs $18.00, and each VHS tape costs $15.00. Declare these as double variables. In addition, recall that class constants are always declared as public static final.

Constructors

The MediaStoreBiller class must have the following two constructors. The first constructor takes no parameters and sets the number of DVDs, books, and VHS tapes to 0. The second constructor sets the number of DVDs, books, and VHS tapes to values that are passed in via parameters.

Accessor Methods

The MediaStoreBiller class must have the following four public accessor methods. the first three methods return the number of DVDs, books, and VHS tapes, respectively, in the customers cart. The computePrice() method computes the price and returns it as a double.

Mutator Methods

The MediaStoreBiller class must have the following public mutator methods. The methods addDVDs(), addBooks(), and addTapes()should add the value specified by the value of the parameter passed to the method to the instance field storing the number of DVDs, books, and VHS tapes, respectively, The methods removeDVDs(), removeBooks() and removeTapes() should subtract the value specified by the value of the parameter passed to the method from the instance field storing the number of DVDs, books, and VHS tapes, respectively.

 

Testing

Your MediaStoreBillerTester class should test each method of the MediaStoreBiller class to ensure that each method functions correctly. To be useful, your MediaStoreBillerTester class should print something that you can use to verify the functionality of each method. It's a good idea to figure out what it should print out and record it in your expected.out file before you run the test. The following is a code fragment that you might include in the main method of your MediaStoreBillerTester class next to the corresponding entry for your expected.out file. Assume that msb is a MediaStoreBiller object that is already instantiated and that each media component has the value 0.

MediaStoreBillerTester
System.out.println("Testing addDVDs(5)");
System.out.println(msb.getDVDs());
msb.addDVDs(5);
System.out.println(msb.getDVDs());
expected.out
Testing addDVDs(5)
0
5

There should be a line in your expected.out file for every line printed out by your MediaStoreBillerTester class.

Front End

We have provided a small GUI application that you can use to see your object in action. The GUI application contains its own main() method, but it requires the MediaStoreBiller class that you have written in order to function. You must implement every method in the MediaStoreBiller class before you can use the GUI. Follow these instructions to download and execute a GUI app that uses your class.

  1. In the Package Explorer pane located on the left side of the Eclipse IDE, right-click on the top-most "MediaStoreBiller" entry and select the "Properties" option.
  2. A new window titled "Properties for MediaStoreBiller" should appear. Select the "Java Build Path" option that appears on the left hand side of this window, and click on the "Libraries" tab.
  3. Click on the "Add External Jar Tab" and enter the following path and filename: W:\u\d\a\dakoop\public\html\cs302\assignments\assignment2\BillerViewer.jar
  4. Click "OK", after which you will be returned to the Eclipse IDE.

If you are working from home, you will have to download and add the BillerViewer.jar file to your Eclipse project. This step is only necessary, if you wish to run the user interface for the MediaStoreBiller Application.

To run the GUI application, right-click on the BillerViewer.jar entry in the Package Explorer pane, and select the "Run" and then "Java Application" options. You should see an application and several buttons that you can click on. Click a few and see what happens!

Note that viewing the behavior of your class using the GUI is not the same as testing your class. The testing that you are required to do is a way of verifying that your code performs exactly according to the specifications. The GUI is simply provided so that you have a convenient way of seeing how the values your MediaStoreBiller class calculates relate to the actual colors that you see.

Javadocs

Documentation for Java source code is almost always provided in a special javadoc format. This documentation is automatically generated from the source code comments, which must follow a special format.

We will be using classes from the Java API in every assignment. The documentation for every class in the Java API can be found at http://java.sun.com/j2se/1.5.0/docs/api.

Requirements

This section outlines the major requirements of the assignment. Your solution to the assignment must meet each of these requirements. Be sure to read the announcements frequently and ask questions if you need clarification.

  1. Include name, login, and section information at the top of all assignment files.
  2. Include javadoc comments for every portion of the public interface of every class.
  3. Use symbolic names wherever they are appropriate.
  4. Follow the MediaStoreBiller specifications exactly, i.e., each method you implement must have the correct spelling, the correct return type, and the correct parameter type(s) and must behave according to the specifications.
  5. The MediaStoreBillerTester class must contain code that tests every method of the MediaStoreBiller class.
  6. The expected.out file must contain the values that you expect the MediaStoreBillerTester class to print out.
  7. Submit your answers to the questions in a text-only file (no Word documents) named questions.txt.
  8. Use the handin instructions to hand in all work electronically.
  9. Use visibility modifiers appropriately; data members should be private and publicly accessible methods should be public .

Output

Some of the questions in this assignment require that you copy and paste into questions.txt the output of your program. See Assignment 0 for the definition of output.

The answers to questions that require program output must be answered with output that is generated by your program.

It is academic misconduct to submit as your output anything other than the output that your program generates. If your program does not produce output (ie. it doesn't work), you may still answer these questions. However, you must clearly state for each question how the answer was obtained.

Questions

This section lists several questions that should deepen your understanding of the assignment. Create a text-only file named questions.txt and answer these questions.

Be sure to include the descriptive information listed below as well as the answers to each question.

Assignment Number: 
Assignment Name:
Date Completed:

Partner 1 Name:
Partner 1 Login:
Partner 1 TA:

Partner 2 Name:
Partner 2 Login:
Partner 2 TA:
  1. Criticize the public interface for MediaStoreBiller specified in the assignment. Were some methods included that you think should have been omitted? Can you think of some methods that should have been included but were not?
  2. What is the purpose of import statements? Did you need to use them in this assignment or could you have done the assignment without? Explain your reasoning.
  3. What was the output from running your MediaStoreBillerTester class? Include the actual text of your output in your answer. Did it match the values in your expected.out file?
  4. Java is case-sensitive. That means that the MediaStoreBiller class and the MediaStorebiller class are not the same class as one spells "Biller" with a capital B, the other with a lower-case b. Would you expect to receive full credit for handing in a class called MediaStorebiller ?
  5. The front end currently tests to make sure that you cannot remove more items than the ones in your cart. Is this check required? If no why? If yes , why and how would you implement it in your code? For example: If you have 3 DVDs, you cannot be allowed to remove 4. What would allowing this do to the price?

Hints

Handin

Use the Handin instructions from the Eclipse Tutorial to hand in your work. Students working in pairs will only submit one copy of all program files, except the README file described below.

Do not hand in .doc, .metadata, *.class, *.jar, or *.html files.

The required files for this assignment are:

Two program files:

One text file of answers to the questions.

One text file of expected output.

Pair Programming Students must also submit a README file.

All students working in pairs must read the Pair Programming Document and submit a README file. Each student working in a pair, must handin this file to their own handin directory. Copy, complete and handin the file that is linked here.