This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Candy Machine Question

 
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.
 
Ranch Hand
Posts: 411
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: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!