• Post Reply Bookmark Topic Watch Topic
  • New Topic

Taking input for ArrayList  RSS feed

 
alfonso vergara
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys;

I am stumped on a coding project I am working on. I am making an inventory program with predefined values for the items.

I am not sure how to iterate through my arrayList, and allow the user to input the "number sold."

I have made an arrayList and populated it using the add(), but I am not sure if it is working correctly. Any feed back on my code is much appreciated.

This is my inventoryItem class


And this is my main class



Please critique as much as possible!
 
Scott Winterbourne
Ranch Hand
Posts: 116
2
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Alfonso!

First, it is considered good practice to declare your instance (object) variables as private and encapsulate them in public getter and setter methods. Take a look at your InventoryItm class.

Next, you can use an enhanced for loop (for each loop) like the one you have on line 30 of your Salesmen class to loop through each item in the ArrayList and display and set values using the getter and setter methods you created in your InventoryItm class.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!