• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Need Help with OOP classes

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys!

So I've been reading much about object oriented programming and started this little program for practice, a Vending machine program.
I've got three classes here:
- VendingMachine
- VendingMachineBox
- VedningMachineTester

And this is what I have so far!


As far as I can tell, the VendingMachine Class is all good.
I'm at a lost with the other two classes below. (There are comments on the parts that I need help with)




If anyone could help guide me with this that would be much appreciated!

Many thanks!
 
Bartender
Posts: 7298
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In this constructor you are passing in itemList, and then in the first line you are overwriting with an empty list. That should be your first hint that it's not correct. I believe you are wanting to add all items in the itemList to the "items" field.
items.addAll(itemList);

I think a better name for your VendingMachine class would be "Item" based on how you use it to create a list of "items". Naming consistency is important.
 
Marshal
Posts: 70234
282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have broken the long lines in your post hich make it very difficult to read and also changed some // comments to /* comments */ because the first type is only suitable for something very short.

If you use the == operator on Strings like that, you can virtually guarantee your program won't work.
 
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic