Project 4

Kevin Nilson

http://www.smccd.net/accounts/nilsonk/

Abstract

CS 381 Project 4, Java Programming I, Fall 06


1. Assignment

Due - September 27

Write a simple Java program that performs like a more advanced cash register.

  • Your Java Classes should use the package edu.smccd.cis381.fall2006.project4

  • Your program must be compatible with project4-build.xml

I expect 5 classes for this assignment

  • CashRegister

  • Money

  • StoreItem

  • Receipt

  • CashRegisterTester

Please review "How to Turn in Assignments" for information about how to submit and other requirements.

2. Description of Classes

Figure 1. UML

UML

Class Diagram for Project 4

3. CashRegisterTester

CashRegisterTester should do the following

  1. Create one or more CashRegisters.

  2. Add some items.

  3. Print the amount due to the customer.

  4. Checkout, which prints a receipt.

  5. Print change given.

  6. Print the balance of the cash register before exiting.

CashRegister cashRegister=new CashRegister();
		
StoreItem item = new StoreItem();
item.setCost(1);
item.setQuantity(10);
item.setDescription("milk");
cashRegister.addItem(item);

item = new StoreItem();
item.setCost(2.20);
item.setQuantity(5);
item.setDescription("bread");
cashRegister.addItem(item);

item = new StoreItem();
item.setCost(10.23);
item.setQuantity(10);
item.setDescription("Jiffy Peanut Butter");
cashRegister.addItem(item);

cashRegister.printoutDue();


Money money = new Money();
money.setNumTwenties(10);

Money change = cashRegister.checkout(money);
System.out.println();
System.out.println("Change given is:");
System.out.println(change);
        

4. CashRegister

  • return null Change if not sufficient funds given to make purchase

  • May make change at any time.

  • No refunds are given, only purchases may be made.

  • The register only keeps track of the total balance, it does not have any idea what bills and coins it has inside.

  • Checkout should print the receipt to the console.

5. Money

  • Don't forget 5 singles is equal to a five dollar bill.

  • When giving change please use as much of the highest value currency as possible. When giving change $27.33 give: 1 twenty, 1 five, 2 singles, 1 quarter, 1 nickle, and 3 pennies.

  • When customers pay they may use any distribution of currency they wish.

6. Receipt

  • Format the receipt last. The format of the receipt String will be graded, but with little weight. Get everything else working first.

  • Try to make your receipt look like mine. You may use a different format if it looks better than mine.

Item Cost = $123.30
Tax = $8.63
Total Due = $131.93

 ---------------------- 
| 10 milk        $10.00|
|  5 bread       $11.00|
| 10 Jiffy Pean $102.30|
|----------------------|
| Item Cost:           |
| $123.30              |
|----------------------|
| Tax:                 |
| $8.63                |
|----------------------|
| Amount Due:          |
| $131.93              |
|----------------------|
| Amount Given:        |
| $200.00              |
|----------------------|
| Change:              |
| $68.07               |
 ---------------------- 


Change given is:
pennies=2 nickels=1 dimes=0 quarters=0 singles=3 fives=1 tens=0 twenties=3 amount=68.07
       	
       	

7. StoreItem

  • Items the customer wants to purchase.

  • You may want to add a toString method.