title: Answer is wrong when calculating future value in java
body: <p>So I am creating a future value application, that allows the user to enter the amount they have invested, the percent per year, how many years it is invested, and if it is compounded annually, semi-annually, monthly, daily, etc.</p>
  
  <p>The problem I am having is that my answer is turning out wrong, but only by a couple hundreds.</p>
  
  <p>With the code I have now, I am using the example for Semi-Annually:</p>
  
  <pre><code>PV = 1000
  Interest Rate = 3
  Years Invested = 10
  Compounded = Semi Annually
  </code></pre>
  
  <p>The answer I get is 1806. </p>
  
  <p>The correct answer is 1346.86, supposedly.</p>
  
  <p>The code I have is here:</p>
  
  <pre><code>    public void actionPerformed(ActionEvent event)
      {
          String input1 = textInitialAmount.getText();
          String input2 = textAnnualInterest.getText();
          String input3 = textNumberOfYears.getText();
          String comp = textCompounded.getText();
  
          double invest = Double.parseDouble(input1);
          double interest = Double.parseDouble(input2);
          double numberofyear = Double.parseDouble(input3);
  
          if(comp.equals("Annually"))
          {
              double compPeriod = 1;
              double compNumberOfYear = numberofyear * compPeriod;
              double rate = (interest / 100) + 1;
  
              double valueFuture = invest * Math.pow(rate, compNumberOfYear);
              String output = String.format("%5.0f", valueFuture);
  
              futureValue.setText("The future value is " + output);
          }
          if (comp.equals("Semi-Annually"))
          {
              double compPeriod = 2;
              double compNumberOfYear = compPeriod * numberofyear;
              double percentRate = interest / 100;
              double rate = percentRate + 1;
  
              double valueFuture = invest * Math.pow(rate, compNumberOfYear);
              String output = String.format("%5.0f", valueFuture);
  
              futureValue.setText("The future value is " + output);
          }
          if(comp.equals("Monthly"))
          {
              double compPeriod = 12;
              double compNumberOfYear = compPeriod * numberofyear;
              double rate = 1 + (interest / 100);
  
              double valueFuture = invest * Math.pow(rate, compNumberOfYear);
              String output = String.format("%5.0f", valueFuture);
  
              futureValue.setText("The future value is " + output);
          }
          if(comp.equals("Bi-Weekly"))
          {
  
          }       
      }
  }
  </code></pre>
  
  <p>Thanks for the help. Please comment if you need me to explain more.</p>