Lab 3 Money In and Money Out:
Note: Viewing current or past student
solutions to this problem
would constitute a violation of Southwestern
University's Honor Code.
Written Design Document and Printouts of the two
prelabs: Feb. 8, 2007
Printouts and Diskette Due and Printed
Grading Sheet: Feb. 15, 2007
PreLab
-
You are to complete the Pairclass
that I
have begun. I will supply the UsePair
class.
A run will look like:
UsePair
Please enter a number:
6
Please enter another number:
7
The sum is 13.0
The difference is -1.0
The product is 42.0
The average is 6.5
The distance is 1.0
The maximum is 7.0
The minimum is 6.0
-
You are to complete the PlayWords
class that
I have begun. -- it would print out like below
Please enter a word: :
antidisestablishmentarianism
The word you entered was :antidisestablishmentarianism
shmentarianismantidisestabli
Please enter a word: giraffe
The word you entered was : giraffe
affegir
-
Save them to you flash Drive and print out the source and execution of
each
Lab Giving Change (P4.11 page 146 --Horstmann, Big
Java)
Implement a program that directs a cashier how to give
change.
The program has two inputs: the amount due and the amount
received
from the customer. Copute the difference, and compute the
dollars,
quarters, dimes nickels an dpennies that the customer should receive in
return.
First transform the difference into an integer balance,
denominated
in pennies. Then compute the whole dollar amount.
Subtract
it from the balance. Compute the number of quarters
needed.
Repeat for dimes and nickels. Display the remaining pennies.
Define a class Cashier wth the methods
-
setAmountDue
-
receive
-
returnDollars
-
returnQuarters
-
returnDimes
-
returnNickels
-
returnPennies
Design Document (Due September 22) Contains
comments for all methods
(constructors, accessors, and modifiers) which tell parameters,
preconditions
and postconditions if appropriate, and method prototype (signature)
line.
Also include a list of all the tests that will prove your program runs.
I have made available the source code from the book example of a Cash
Register: CashRegister.java
, CashRegisterTester.java
and InputTester.java
/**
Sets the amount due
@param double dueAmount the
amount owed
@post condition the private instance
variable owed
has been changed
*/
public setAmountDue (double
dueAmount)
<--this line is the method prototype
{
}
For example a TestCashier program might have:
Cashier harry = new Cashier();
harry.setAmountDue(9.37);
harry.receive(10);
int quarters = harry.returnQuarters(); //returns 2
int dimes = harry.returnDimers(); // returns 1
int nickels = hayy.returnNickels(); // returns 0
int pennies = harry.returnPennies(); // returns 3
Then you would print out values so that the output would look like:
TestCashier
Amount due: 9.37 Amount given: 10.00
Give the customer
0.0 dollars,
2.0 quarters,
1.0 dimes,
0.0 nickels,
3.0 pennies
{ Be sure to include several other test cases to that you have made
sure
that you can return all denominations)
*Note -- to account for innacurate conversions of decimals to
int --
(int)(Math.round(change*100))
You must:hand in:
-
printouts of the run of TestCashier using several Cashier
objects,
not just harry!
-
printout of the Cashier.java and TestCashier.java programs
-
have the programs Cashier and TestCashier on the flash drive in a
folder called
Cashier