title: Java, list of objects, change values in a loop
body: <p>My program has 4 <code>Computer</code> objects with different values, from <code>Make</code>, <code>Model</code>, <code>Productnumber</code>, <code>Amount</code>, and <code>Shelfnumber</code>.
  They are coming from a class <code>Computer</code> which extends from class <code>Product</code>. I add the objects to an object list, now I need to get the <code>Shelfnumber</code>s (the last value in the objects) from each object and add a different amount to them depending on what the values are.</p>
  <p>The question I have is, is there any way to go through each of the objects in a loop. The current loop only does it for the first computer object, <code>t1</code>. Now I would need it to get the <code>Shelfnumber</code> for <code>t2</code>, <code>t3</code> and <code>t4 </code>in the same loop.</p>
  <p>I.e., get <code>t1</code>'s Shelfnumber -&gt; check what the value is -&gt; add to it -&gt; get <code>t2</code>'s <code>Shelfnumber</code> and do the same.</p>
  <pre><code>public class Main {
  
      public void computers() {
          ArrayList&lt;Object&gt; computers = new ArrayList&lt;Object&gt;();
          Computer t1 = new Computer(&quot;Razer&quot;, &quot;Blade 15&quot;, &quot;65732&quot;, 3, 12); computers.add(t1);
          Computer t2 = new Computer(&quot;Apple&quot;, &quot;MacBook Pro&quot;, &quot;8732&quot;, 21, 15); computers.add(t2);
          Computer t3 = new Computer(&quot;Asus&quot;, &quot;Aspire 5&quot;, &quot;7532&quot;, 5, 2); computers.add(t3);
          Computer t4 = new Computer(&quot;Lenovo&quot;, &quot;Legion 5&quot;, &quot;3437&quot;, 2, 150); computers.add(t4);
          int shelfNumber = 0;
  
          for (int i = 0; i &lt; computers.size(); i++) {
              shelfNumber = t1.getShelfnumber();
              if (shelfNumber &lt; 10) {
                  shelfNumber = shelfNumber + 10;
              } else if (shelfNumber &gt; 10 &amp;&amp; shelfNumber &lt; 100) {
                  shelfNumber = shelfNumber + 30;
              } else {
                  shelfNumber = shelfNumber + 500;
              }
          }
          System.out.println(shelfNumber);
  
          System.out.println(t1.toString());
          System.out.println(t2.toString());
          System.out.println(t3.toString());
          System.out.println(t4.toString());
      }
  
      public static void main(String[] args) {
          Main ohj = new Main();
          ohj.computers();
      }
  }
  </code></pre>