• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Candy Machine Question  RSS feed

 
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!