Using the Eclipse Java EE Edition IDE and Java 8 complete the following exercise. If you are able to easily complete this exercise then you have a proficiency level beyond our Java Programming II course.

1) Requirements

A new candy machine is bought for the school. The machine sells candy, gum, chips and
cookies. Start an OO Java application for this candy machine so that it can eventually be put into
operation.

candy-machine

The application should do the following:

  1. Initialize the Vending Machine from a database table using MySQL and JDBC.
  2. A:1 Snickers is Candy for $0.75

    B:2 Oreos are Cookies for $0.85

    C:3 Hubba Bubba is Gum for $0.65

    D:4 Ruffles Plain are Chips for $0.80

  3. Show the customer the different products sold by the machine.
  4. Show the customer the cost of the item selected.
  5. Let the customer make a selection.
  6. Accept money from the customer.
  7. Check that the money entered is enough to buy the item. If not ask for more, or ask if change return pressed. Repeat this until enough money.
  8. If there is enough money, deliver the item.
  9. Return any change.
  10. Repeat

2) Activity Diagram

OO Candy Machine Flow Chart

OO Candy Machine Flow Chart

3) Class Diagram

Here is a completed class diagram of a working vending machine application:
candymachine

4) Sample Output

If you’ve implemented the VendingServiceImpl correctly you should be able to generate the output below if you enter the same inputs as shown.

A:1 Snickers is Candy for $0.75

B:2 Oreos are Cookies for $0.85

C:3 Hubba Bubba is Gum for $0.65

D:4 Ruffles Plain are Chips for $0.80


Enter Your Selection Location?
B:2
Your Selection: Oreos are Cookies
 Enter $0.85 please.
Enter Your Money or "Return Change"?
0.25
Your Selection: Oreos are Cookies
 Enter $0.85 please.
Current Balance is $0.25

Enter Your Money or "Return Change"?
0.25
Your Selection: Oreos are Cookies
 Enter $0.85 please.
Current Balance is $0.50

Enter Your Money or "Return Change"?
0.10
Your Selection: Oreos are Cookies
 Enter $0.85 please.
Current Balance is $0.60

Enter Your Money or "Return Change"?
1.00
Pick up your item. Enjoy your Oreos!

$0.75 Returned to Customer
Thank You. Have a nice day.
A:1 Snickers is Candy for $0.75

B:2 Oreos are Cookies for $0.85

C:3 Hubba Bubba is Gum for $0.65

D:4 Ruffles Plain are Chips for $0.80


Enter Your Selection Location?
Enter Your Selection Location?
D4
Your Selection: Ruffles Plain are Chips
 Enter $0.80 please.
Enter Your Money or "Return Change"?
.50
Your Selection: Ruffles Plain are Chips
 Enter $0.80 please.
Current Balance is $0.50

Enter Your Money or "Return Change"?
return
$0.50 Returned to Customer
Thank You. Have a nice day.
A:1 Snickers is Candy for $0.75

B:2 Oreos are Cookies for $0.85

C:3 Hubba Bubba is Gum for $0.65

D:4 Ruffles Plain are Chips for $0.80


Enter Your Selection Location?

5) Final Project

Export and send me your final project (or progress) for the OOCandyMachineProj and/or your list of questions/observations.

I hope you enjoyed building the Object Oriented Candy Machine and learned a lot from the experience. Keep up the good work!

Make a better Candy Machine and share, there is plenty of room for improvement!