Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Candy Machine Question

 
Chase Parsons
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
As my last assignment in my beginner java course, I am tasked with building a candy machine. This machine will need to appropriately throw exceptions when needed. I have completed the majority of the project. I just need help writing my main method. I am basically stuck on a simple issue: how to assign my values. I thought about constructing an array, but I am hesitant on doing such. The only output needed is "Thank you for your purchase", but my program must "sell" the piece of candy to do so. So basically, if I do not throw an exception, my ONLY output will be that String.

Here is my main class:


And my Dispenser class:


And finally, CashRegister:


Thank you in advance.
 
Rico Felix
Ranch Hand
Posts: 407
5
IntelliJ IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chase Parsons wrote:The only output needed is "Thank you for your purchase", but my program must "sell" the piece of candy to do so. So basically, if I do not throw an exception, my ONLY output will be that String.


Basically all that needs to be done is some declarations and instantiations for each object in your application and pass the required two objects to the function call

Here is an illustration from which you can acquire ideas to meet your specific requirement:

 
Chase Parsons
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
I really drew a blank here as the semester is coming to a close. I was able to tweak some code and incorporate your suggestions in order to complete a successful project!
 
Rico Felix
Ranch Hand
Posts: 407
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic