title: Java select object instance based on variable
body: <p>I have a really annoying assignment which requires me to create 3 instances of a object and I need to create methods to modify and access them for use in another class.
  I know the simplest and best way to do this would be to use an array, but I'm not supposed to know about those yet and the assignment requires I NOT use them.</p>
  
  <p>So basically I'm looking for a way to interact with each of the objects based on another variable.</p>
  
  <p>For example I have the following instances of my object:</p>
  
  <p>object1
  object2
  object3</p>
  
  <p>What I want to be able to do is create a variable objectNo, and use the number of that variable to select object 1, 2 or 3</p>
  
  <p>Instead of having a bunch of if statements and writing the same code 3 times where the only difference is the object name as I have it currently below:</p>
  
  <pre><code>public void updateObject (int argNo, String argName)
  {
  private int objectNo = argNo;
  private String productName = argName;
  if (objectNo == 1)
      {
          object1.name = productName
  
      }
  
  else if (objectNo == 2)
      {
          object2.name = productName
          ...
      }
  </code></pre>
  
  <p>Any suggestions, I'm new to Java and this is doing my head in.</p>