Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Taking input for ArrayList

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!
Ranch Hand
Posts: 116
Eclipse IDE PHP Java
  • 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.
It's feeding time! Give me the food you were going to give to this tiny ad:
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic