title: Programming a Savings Account Java Table to show an increment of 2
body: <p>I'm working on a network application for my class.  Basically I have to write java and jsp to make a site that gives the .jsp output below (which is preceded by a .jsp page that asks for the balance, rate, and period).  I'm writing the java for it now and I'm trying to make a html table with the Java class.</p>
  
  <p>The problem I'm having is to make it so that the table is showing the standard deviation of 2 for the rate (rows) and period (columns).  Instead of just adding all of the information for all periods and rates.  How do I narrow it?  </p>
  
  <p><em>note: I know the code in my table is really not correct at all, I think everything else is OK though</em></p>
  
  <p>My Code so far:</p>
  
  <pre><code>    package SavingAcct;
  
      import java.text.*;
  
      public class savingsAccount {
  
  private double rate;
  private double currentBalance;
  private int term;
  
  public savingsAccount() {
  
      this.rate = 0.00;
      this.currentBalance = 0.00;
      this.term = 0;
  
  
  }
  
  public savingsAccount(double rate, double currentBalance, int term) {
  
      this.rate = rate;
      this.currentBalance = currentBalance;
      this.term = term;
  
  
  }
  
  /**
   * @return the term
   */
  public int getTerm() {
      return term;
  }
  
  /**
   * @param term the term to set
   */
  public void setTerm(int term) {
      this.term = term;
  }
  
  /**
   * @return the rate
   */
  public double getRate() {
      return rate;
  }
  
  /**
   * @param rate the rate to set
   */
  public void setRate(double rate) {
      this.rate = rate;
  }
  
  /**
   * @return the balance
   */
  public double getBalance() {
  
      return currentBalance;
  }
  
  /**
   * @param balance the balance to set
   */
  public void setBalance(double balance) {
      this.currentBalance = balance;
  }
  
  public String doSavingsAccount() {
      String htmlSavingsTable = "";
  
  
      NumberFormat cf = NumberFormat.getCurrencyInstance();
      NumberFormat pf = NumberFormat.getPercentInstance();
  
      //start the html table
      htmlSavingsTable = "&lt;table border='2'&gt;";
      //create a table heading
      htmlSavingsTable += "&lt;tr&gt;";
      htmlSavingsTable += "&lt;td&gt;&lt;b&gt;  -  &lt;/b&gt;&lt;/td&gt;";
      htmlSavingsTable += "&lt;td&gt;&lt;b&gt;" + (term-2) + "&lt;/b&gt;&lt;/td&gt;";
      htmlSavingsTable += "&lt;td&gt;&lt;b&gt;" + (term-1) + "&lt;/b&gt;&lt;/td&gt;";
      htmlSavingsTable += "&lt;td&gt;&lt;b&gt;" + term + "&lt;/b&gt;&lt;/td&gt;";
      htmlSavingsTable += "&lt;td&gt;&lt;b&gt;" + (term+1) + "&lt;/b&gt;&lt;/td&gt;";
      htmlSavingsTable += "&lt;td&gt;&lt;b&gt;" + (term+2) + "&lt;/b&gt;&lt;/td&gt;";
      htmlSavingsTable += "&lt;/tr&gt;";
  
      for (double rate = this.getRate()-2; rate &lt;= getRate()+2;){
  
  
          // start html table row for 
          htmlSavingsTable += "&lt;tr&gt;";
          // add rate to row
          htmlSavingsTable += "&lt;td&gt;&lt;b&gt;" + pf.format(rate-2) + "&lt;/b&gt;&lt;/td&gt;";
          // add monthly payment to row
          htmlSavingsTable += "&lt;td&gt;&lt;b&gt;" + cf.format(getNewBalance())+     "&lt;/b&gt;&lt;/td&gt;";
          // end the row
          htmlSavingsTable += "&lt;/tr&gt;";
  
  
      }
      // end the table
      htmlSavingsTable += "&lt;/table&gt;";
  
      return htmlSavingsTable;
  
  }
  
  public double getNewBalance() {
      double newBalance;
      newBalance = currentBalance * (Math.pow((1+rate), term));
      return newBalance;
  }
  
  
      }
  </code></pre>