title: Java - Field in parent class not changing
body: <p>So, I have a variable in a parent class that I am trying to change in a subclass with getter/setter methods. But, the value is just staying the same and I have no idea why.. What am I doing wrong? Any help is appreciated!</p>
  
  <ul>
  <li><p>Here is a breakdown of the program: In the driver class, you choose what you want to do, then it uses the current value variable and a number you choose (operand2) to get the answer. The add, subtract, multiply and divide are in the memory calculator class. It can also clear, which sets the current value variable to zero. Now, we are adding a sub class to it that does exponents and logarithms.</p></li>
  <li><p>specifics: The variable currentValue in the MemoryCalc class stays the same when I try to use the power or log methods in the ScientificMemCalc class. In that class it uses a getter method to get the current value and then attempts to use a setter method to change the current value. But nothing changes. And another problem: the getter method gets a zero value from the currentValue field.</p></li>
  </ul>
  
  <p>Here is driver class with main method: </p>
  
  <pre><code>package ScientificMemCalc;
  
  import java.util.Scanner;
  
  import ScientificMemCalc.MemoryCalc;
  
  public class ScientificCalcDriver {
  
      public static void main(String[] args) {
  
      Scanner input = new Scanner(System.in);
  
      MemoryCalc calculator = new MemoryCalc();
      ScientificMemCalc scientificCalc = new ScientificMemCalc();
  
  
      int menu = 0;
      double operand2, answer;
  
      while (menu !=8) {
  
          answer = calculator.getCurrentValue();
          System.out.println("The current value is: " + answer);  
  
          menu = getMenuOption();
  
          switch(menu) {
          case 1:
              // Add
              operand2 = calculator.getOperand("What is the second number?: ");
              calculator.add(operand2);
              break;
  
          case 2:
              // Subtract
              operand2 = calculator.getOperand("What is the second number?: ");
              calculator.subtract(operand2);
              break;
  
          case 3:
              // Multiply
              operand2 = calculator.getOperand("What is the second number?: ");
              calculator.multiply(operand2);
              break;
  
          case 4:
              // Divide
              operand2 = calculator.getOperand("What is the second number?: ");
              calculator.divide(operand2);
              break;
  
          case 5:
              // Power
              operand2 = calculator.getOperand("What is the second number?: ");
              scientificCalc.power(operand2);
              break;
  
          case 6:
              // Logarithm
              scientificCalc.log();
              break;
  
          case 7:
              // Clear
              operand2 = 0;
              calculator.clear();
              break;
  
          case 8:
              // Quit
              System.out.println("Goodbye!");
              break;
          }
      }
  }
  
  public static int getMenuOption() {
  
      Scanner input = new Scanner(System.in); 
  
      int choice = 0;
  
      // Display menu
      System.out.println("Menu:");
      System.out.println("1. Add");
      System.out.println("2. Subtract");
      System.out.println("3. Multiply");
      System.out.println("4. Divide");
      System.out.println("5. Power");
      System.out.println("6. Logarithm");
      System.out.println("7. Clear");
      System.out.println("8. Quit");
  
      // Get menu input
      System.out.print("What would you like to do?: ");
      choice = input.nextInt();
  
      while (choice &lt; 1 || choice &gt; 8) {
          System.out.print("Invalid. Try again: ");
          choice = input.nextInt();
      }
  
      return choice;
      }
  }
  </code></pre>
  
  <p>Here is the memory calculator class: </p>
  
  <pre><code>package ScientificMemCalc;
  
  import java.util.Scanner;
  
  public class MemoryCalc {
  
  private double currentValue;
  
  public double getOperand(String prompt) {
  
      Scanner input = new Scanner(System.in);
  
      System.out.print(prompt);
      return input.nextDouble();
  
  }
  public double getCurrentValue() {
      return currentValue;
  }
  public void setCurrentValue(double temp) {
      currentValue = temp;
  }
  public void add(double operand2) {
      // Add
      currentValue += operand2;
  }
  public void subtract(double operand2) {
      // Subtract
      currentValue -= operand2;
  }
  public void multiply(double operand2) {
      // Multiply
      currentValue *= operand2;
  }
  public void divide(double operand2) {
      // Divide
      if (operand2 == 0) {
          System.out.println("You cannot divide by zero!");
          currentValue = Double.NaN;
      }
      else {
          currentValue /= operand2;
      }
  }
  public void clear() {
      // Clear
      currentValue = 0;
  
      }
  }
  </code></pre>
  
  <p>And finally the subclass to add scientific functions:</p>
  
  <pre><code>package ScientificMemCalc;
  
  public class ScientificMemCalc extends MemoryCalc {
  
  public void power(double operand2) {
      // Power
      double currentValue = getCurrentValue();
      double temp = Math.pow(currentValue, operand2);
      setCurrentValue(temp);
  }
  public void log() {
      // Logarithm
      double currentValue = getCurrentValue();
      double temp = Math.log(currentValue);
      setCurrentValue(temp);
      }
  
  }
  </code></pre>