title: Trouble with APCS Assignment on CodeHS
body: <p><strong><em>Hi, I am working on a CodeHS problem and completed it with confidence, but got it very wrong. I am looking for my mistakes and helpful feedback. Thanks!</em></strong></p>
  
  <p>*The instructions for the problem are as follows:</p>
  
  <p>We have a simple Battery class. Add two static fields to Battery, 
  totalVoltage and numOfBatteries. In addition, alter the constructor so that
  the Battery class keeps track of both of the new static variables.
  Every time a new Battery is constructed, the numOfBatteries should increase by one, and the totalVoltage should increase by the new voltage of the current Battery being constructed.
  Hint: totalVoltage should be a double*</p>
  
  <p><strong>The Batterytester is:</strong></p>
  
  <pre><code>public class BatteryTester extends ConsoleProgram
  {
      public void run()
      {
          Battery aaBattery1 = new Battery(1.5);
          System.out.println("Total voltage: " + Battery.totalVoltage);
          System.out.println("Total batteries: " + Battery.numOfBatteries);
  
          Battery aaBattery2 = new Battery(1.5);
          System.out.println("Total voltage: " + Battery.totalVoltage);
          System.out.println("Total batteries: " + Battery.numOfBatteries);
  
          Battery aaBattery3 = new Battery(1.5);
          System.out.println("Total voltage: " + Battery.totalVoltage);
          System.out.println("Total batteries: " + Battery.numOfBatteries);
  
          Battery aaBattery4 = new Battery(1.5);
          System.out.println("Total voltage: " + Battery.totalVoltage);
          System.out.println("Total batteries: " + Battery.numOfBatteries);
  
      }
  }
  </code></pre>
  
  <p><strong>My code is as follows:</strong></p>
  
  <pre><code>public class Battery
  {
      private double voltage;
      public static int numOfBatteries;
      public static double totalVoltage;
  
      //adds the new fields to constructor 
      public Battery(double voltage, double totalVoltage, int numOfBatteries)
      {
          this.voltage = voltage;
          this.totalVoltage = totalVoltage;
          this.numOfBatteries = numOfBatteries;
          numOfBatteries++;
          totalVoltage += voltage; //increments total voltage with voltage param
      }
  
      public double getVoltage()
      {
          return this.voltage;
      }
  
      public static int numOfBatteries()
      {
          return this.numOfBatteries;
      }
  
      public static double totalVoltage()
      {
          return this.totalVoltage;
      }
      //all of these return the values
  }
  </code></pre>