Java: Invoking Methods From Class / null logic error
<p>I'm having a hard time wrapping my head around object based programming.  Im attempting to invoke a method from a class.  However, all I invoke is a variable that has been declared, while I'm trying to pull the variable later. (Im sure my terminology is off - feel free to correct) </p>

<p>Im getting logic errors. Instead of a value, im getting "null".</p>

<p>The Class:</p>

<pre><code>public class NumberOperations {
   int number;
   String oddsUnder;
   String powersTwoUnder;
   int isGreater;
   String toString;



public NumberOperations(int numberIn) {
   number = numberIn;

}

public int getValue() {
   return number;
}

public String oddsUnder() {
   String output = "";
   int i = 0;
   while (i &lt; number) {
      if (i % 2 != 0) {
         output += i + "\t";
      }
      i++;   
   }
   return output;
}

public String powersTwoUnder() {
   String output2 = "";
   int powers = 1;
   while (powers &lt; number) {
   output2 += powers + "\t";
   powers = powers * 2;
   }
   return output2;
}

public int isGreater(int compareNumber) {
   if (number &gt; compareNumber) {
      return 1;
   }
   else if (number &lt; compareNumber) {
      return -1;
   }
   else {      
      return 0;
   }   
}

public String toString() {
   return number + "";
}

}          
</code></pre>

<p>The Program:</p>

<pre><code>import java.util.Scanner; import java.util.ArrayList;

/**  * Demonstrates the NumberOperations class.  */ public class NumberOpsDriver {

   /**
    * Reads a set of positive numbers from the user until the user enters 0.     * Prints odds under and powers of 2 under for each number.      *
    * @param args - Standard commandline arguments
    */    public static void main(String[] args) {

      Scanner in = new Scanner(System.in);

      // declare and instantiate ArrayList with generic type &lt;NumberOperations&gt;
      ArrayList&lt;NumberOperations&gt; numOpsList = new ArrayList&lt;NumberOperations&gt;();

      // prompt user for set of numbers
      System.out.println("Enter a list of positive integers separated "
                        + "with a space followed by 0:");

      // get first user input using in.nextInt()
      int firstInput = in.nextInt();
      // add a while loop as described below:
      while (firstInput != 0) {

         numOpsList.add(new NumberOperations(firstInput));

         firstInput = in.nextInt();
      }     

    // while the input is not "0"
         // add NumberOperations object to array based on user input
         // get the next user input using in.nextInt()

      int index = 0;
      while (index &lt; numOpsList.size()) {
         NumberOperations num = numOpsList.get(index);
         System.out.println("For: " + num);
         System.out.println("Odds under: " + num.oddsUnder);
         System.out.println("Powers of 2 under: " + num.powersTwoUnder);

        // add print statement for odds under num
        // add print statement for powers of 2 under num

         index++;
      }    } }
</code></pre>
