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

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
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!