• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Help with OOP classes  RSS feed

 
Adam Dorian
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!
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor 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.
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!