title: trouble reading variables in an array of reference java
body: <p>i am reading from a csv file that reads a country name and takes a subscription data  for a particular country at a certain year. Below is a csv sample file:</p>
  
  <pre><code>CountryName,1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012
  Aruba,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.029310471,0,0,2.138784453,3.605985937,3.98141538,6.16435217,13.48254011,16.50927821,57.05427692,65.05605558,72.10431377,99.64250268,103.3849507,108.1325002,112.2180618,119.2038996,126.2103374,129.72824,0,131.8565401               
  Andorra,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.307211734,1.278625641,1.250259142,4.424155104,8.538444783,13.44671556,22.12730607,32.14530928,35.99902139,43.27794118,45.77115817,68.60251444,73.82494308,79.48487497,84.27763597,78.1171579,80.2836099,82.06181111,84.06818386,83.53432222,81.50204186                         
  Afghanistan,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.112598381,0.865196277,2.498055472,4.826865367,9.833164022,17.71624331,29.22037376,37.89493697,45.77817474,60.32631999,60.35299258
  </code></pre>
  
  <p>I am able to read the file fine. I created 2 classes. 1 class called <code>class subscriptionYear</code> that reads the year that i called <code>int year</code>, and variable <code>double subscription</code> that reads each stats data. 2nd class called <code>Class Country</code>. It reads the country called <code>String countryNames</code> and a 1d array called <code>SubscriptionYear[] subscriptions</code> which holds all the subscription data for that country. I have 2 methods in class country called <code>addSubscriptionYear(int year, double countryData)</code> which reads the data  I am to follow the guideline of the test class called <code>class TestCountry</code>. My program reads the file but outputting the wrong sum. Basically it reads only 2012 and not the entire period between 1960 and 2012. so when i do the sum it is only outputs the stats of 2012 and not the entire sum of from 1960 to 2012. My problem seems to be from <code>addSubscriptionYear method</code> which inserts the year and data into the <code>class Subscription</code> but it only reads the year 2012 and not the entire period from 1960 to 2012 when i tried debugging it. I have to follow the guidelines from <code>TestCountry class</code> as this is the requirement. But my function method <code>addSubscriptionYear()</code> is the problem. Could some one please help me out or some tips how to store each year and data in the array of objects. Below is my file</p>
  
  <p>class Subscription:</p>
  
  <pre><code>public class SubscriptionYear {
  
  private int year;
  private double subscriptions;
  
  public SubscriptionYear(int year,double subscriptions)
  {
      //this.year = year;
      //this.subscriptions = subscriptions;
      setYear(year);
      setSubscription(subscriptions);
  }
  public void setYear(int Year)
  {
      this.year= Year;
  }
  public void setSubscription(double value)
  {
      this.subscriptions = value;
  }
  public int getYear()
  {
      return year;
  }
  public double getSubscription()
  {
      return subscriptions;
  }
  public String toString()
  {
      return "Number of Subscriptions: "+subscriptions;
  }
  }
  </code></pre>
  
  <p>class Country:</p>
  
  <pre><code>public class Country {
  
  private String countryNames;
  private SubscriptionYear[] subscriptions;
  private int size;
  
  public Country(String country, int arraylength)
  {
      this.countryNames = country;
      this.size = arraylength;
      subscriptions = new SubscriptionYear[size];
  }
   //seems to be where i am having the problem
   //only reads 2012 and not 1960. seems to be my problem
  public void addSubscriptionYear(int year, double subscription)
  {
      for(int i=0;i&lt;subscriptions.length;i++)
      {
          subscriptions[i]= new SubscriptionYear(year, subscription);
      }
          //System.out.print(subscriptions[0].getYear()+"\t");
  
  }
  public double getNumSubscriptionsForPeriod(int start, int end)
  {
      double sum = 0;
      int head = subscriptions[0].getYear()-start;
      int tail = end-start;
      if(head&gt;=0&amp;&amp;end&lt;subscriptions.length)/check if out of bounds.
      {
      for(int k=head;k&lt;=tail;k++)
      {
          sum += subscriptions[k].getSubscription();
      }
     } else{ sum =-1;}
     return sum;
  }
  public String toString()
  {
      System.out.print(countryNames+"\t");
      for(SubscriptionYear s: subscriptions)
      {
          //System.out.print(countryNames+"\t");
          System.out.print(s.getSubscription()+"\t");
      }
      System.out.println();
      return  "";
  }
  }
  </code></pre>
  
  <p>Tesfile:</p>
  
  <pre><code>/**
   *  Tests the Country class by creating multiple objects.
   *  Creates one object of type CSVReader class, which reads input from a CSV file. Uses
   *  the attributes stored in CSVReader object to create objects of type Country class.
   */
  public class TestCountry 
  {
  
  /**
   * Includes test examples for class Country.
   */
  public static void main(String[] args) 
  {
      // Create and set objects of type Country 
      //
      final String FILENAME = "data/cellular.csv";    // Directory path for Mac OS X
      //final String FILENAME = "data\cellular.csv";  // Directory path for Windows OS (i.e. Operating System)
      final int NUM_COUNTRIES_TO_TEST = 3;            // Note: Include test cases in addition to 3
  
  
      // Parse the CSV data file
      //
      CSVReader parser = new CSVReader(FILENAME);
  
      String [] countryNames = parser.getCountryNames();
      int [] yearLabels = parser.getYearLabels();
      double [][] parsedTable = parser.getParsedTable();      
  
  
      // Create and set objects of type Country 
      //
      Country [] countries;
      //countries = new Country[NUM_COUNTRIES_TO_TEST];   // Note: Use this for initial testing of your implementation.
      countries = new Country[countryNames.length];                
  
      Country current;
  
      for (int countryIndex = 0; countryIndex &lt; countries.length; countryIndex++)
      {
          int numberOfYears = yearLabels.length;   // OR numberOfYears = dataTable[countryIndex].length;
  
          current = new Country(countryNames[countryIndex], numberOfYears);
  
          for (int yearIndex = 0; yearIndex &lt; numberOfYears; yearIndex++)
          {
              double [] allSubscriptions = parsedTable[countryIndex];
              double countryData = allSubscriptions[yearIndex];
              current.addSubscriptionYear(yearLabels[yearIndex], countryData);
          }
          countries[countryIndex] = current;
      }
          //for(int i =0;i&lt;countries.length;i++)
          //{
      //System.out.print(countries[8]);
          //}
          //System.out.println();
      System.out.printf(countryNames[0] + " (1960 to 2012): %.2f \n", countries[0].getNumSubscriptionsForPeriod(1960,2012));
      // the output is 131.63 and should be 1170.50 
  
      System.out.printf(countryNames[100] + " (1960 to 2012): %.2f \n", countries[100].getNumSubscriptionsForPeriod(1960,2012));
      // the output is 112.67 and should be 1246.58 
  }
   }
  </code></pre>
  
  <p>It outputs 131.63 for aruba and not 1170.50. It basically only reads stats for 2012 and not entire period of 1960 to 2012. I need help on fixing addSubscriptionYear method in class Country. </p>