Tuesday, October 28, 2008

Major Assignment 4 Due Friday November 7th, 2008

Exercise P12.6.
Write a program that simulates a vending machine. Products can be purchased by inserting coins with a value at least equal to the cost of the product. A user selects a product from a list of available products, adds coins, and either gets the product or gets the coins returned if insufficient money was supplied or if the product is sold out. The machine does not give change if too much money was added. Products can be restocked and money removed by an operator. Follow the design process that was described in this chapter. Your solution should include a class VendingMachine that is not coupled with the Scanner or PrintStream classes.

Here is a sample program run:
S)how products  I)nsert coin  B)uy  A)dd product  R)emove coins  Q)uit
A
Description:
Candy bar
Price:
0.55
Quantity:
10
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
A
Description:
Fruit drink
Price:
0.65
Quantity:
10
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
S
Candy bar @ $0.55
Fruit drink @ $0.65
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
I
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
C
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
I
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
C
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
I
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
A
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
B
A) Candy bar @ $0.55
B) Fruit drink @ $0.65
A
Purchased: Candy bar @ $0.55
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
I
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
D
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
B
A) Candy bar @ $0.55
B) Fruit drink @ $0.65
B
Purchased: Fruit drink @ $0.65
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
R
Removed: $1.55
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
Q
Your main class should be called VendingMachineSimulation.

Put it on your FTP space. Due Friday, November 7th, 2008.
I'd like you to continue working on the BlackJack game...that will be the next Major Assignment.

No comments: