title: Having trouble understanding how to maintain state using classes
body: <p>I'm new to using OOP, I typically just put all my code in a single class and use methods. But I want to maintain state information and think classes are the best fit but I'm having trouble wrapping my head around it.  </p>
  
  <p>Say I have a list of items and I want to stop when the total sum of all previous items in the list equals X(in this case 10 so it takes item 1 + 2, then 2+3.etc..until it hits the threshold 10), I can use a method to calculate it but it involves me doing the entire process all over again when all I really need to do is increment by the last item and then see if my data exceeds the threshold.  Here's my code so far but I know its not good because although it works its really just using the class as an independent method and recalculating on every loop.  My goal is to,using this structure, reduce loops if not necessary to check thresholds.</p>
  
  <p>Any suggestions?</p>
  
  <p>Code:</p>
  
  <pre><code>public class LearningClassesCounter {
      public static void main(String[] args) {
          int[] list = new int[]{1,2,3,4,5,6,7,8,9,10};
          int[] data_list = new int[list.length];
          for (int current_location = 0; current_location&lt;list.length;current_location++) {
              //can only put commands in here. Nothing above.
              Counter checker = new Counter(data_list);
              System.out.println(checker.check_data(current_location));
              for (int i =0; i&lt;100; i++){
                  if (checker.check_data(current_location) == false) {
                      break;
                  }
                  data_list[current_location] = (list[current_location]+1); //this is just a random function, it could be any math function I just put it in here to show that some work is being done.
              }
          }
          //its done now lets print the results
          for (Integer item : data_list) {
              System.out.println(item);
          }
      }
  }
  
  
  class Counter {
      private int[] data_list;
      private int total_so_far;   
      // create a new counter with the given parameters
      public Counter(int[] data_list) {
          this.data_list = data_list;
          this.total_so_far = 0;
      } 
  
      public boolean check_data(int current_location) {   
          // TODO Auto-generated method stub
          int total_so_far = 0;
          //System.out.println(total_so_far);
          for (int item : data_list) {
              total_so_far = item + total_so_far;
              if (total_so_far &gt;= 10) {
                  break;
              }
          }
  
          if (total_so_far&gt;=10) {
              return false;
          } else {
              return true;
          }
      }
  
  }
  </code></pre>
  
  <p>I don't need anyone to fix my code or anything(I want to do it myself, the code is just to give an idea of what I'm doing).  I'm more interested in the flaw in my logic and maybe a way for me to better think about designing classes so I can apply them to my own situations better.</p>