title: Loan calculator using tableview in JavaFX
body: <p>I am attempting to make a loan calculator that shows payment number, interest, principal, and balance in tableview in JavaFX. Right now only the principal and balance columns are populating. I am fairly new to JavaFX, so I am not sure if I have made a mistake in FX or in my formula. Here is my code:</p>
  
  <pre><code>public class LoanTable extends Application {
  Integer payment;
  Double interest;
  Double principal;
  Double balance;
  @Override 
  public void start(Stage primaryStage) {
      BorderPane border = new BorderPane();
      GridPane grid = new GridPane();
      ScrollPane scroll = new ScrollPane();
      Label labelTitle = new Label("Enter Loan Amount, Number of Years, and     Annual Interest Rate");
      labelTitle.getStyleClass().add("labelTitle");
      Label loan = new Label("Loan Amount");
      TextField loanAmount = new TextField();
      Label years = new Label("Number of Years");
      TextField numYears = new TextField();
      Label interestRate = new Label("Annual Interest Rate");
      TextField rate = new TextField();
      Button compute = new Button("Display Loan Schedule");
  
      TableView&lt;Finance&gt; table = new TableView&lt;&gt;();
  
      TableColumn paymentColumn = new TableColumn("Payment#");
      paymentColumn.setMinWidth(200);
      paymentColumn.setCellValueFactory(new PropertyValueFactory&lt;Finance, Integer&gt;("payment"));
  
      TableColumn interestColumn = new TableColumn("Interest");
      interestColumn.setMinWidth(200);
      interestColumn.setCellValueFactory(new PropertyValueFactory&lt;Finance, Double&gt;("interest"));
  
      TableColumn prinColumn = new TableColumn("Principal");
      prinColumn.setMinWidth(200);
      prinColumn.setCellValueFactory(new PropertyValueFactory&lt;Finance, Double&gt;("principal"));
  
      TableColumn balColumn = new TableColumn("Balance");
      balColumn.setMinWidth(200);
      balColumn.setCellValueFactory(new PropertyValueFactory&lt;Finance, Double&gt;("balance"));
  
      table.getColumns().addAll(paymentColumn, interestColumn, prinColumn, balColumn);
  
      grid.add(labelTitle, 0, 0);
      grid.add(new Label(), 0, 1);
      grid.add(loan, 0, 2);
      grid.add(loanAmount, 1, 2);
      grid.add(years, 0, 3);
      grid.add(numYears, 1, 3);
      grid.add(interestRate, 0, 4);
      grid.add(rate, 1, 4);
      grid.add(compute, 4, 0);
  
      scroll.setContent(table);
  
      border.setTop(grid);
      border.setBottom(scroll);
  
      Scene scene = new Scene(border, 800, 800);
      scene.getStylesheets().add("loan_table.css");
  
      primaryStage.setScene(scene);
      primaryStage.show();
  
      compute.setOnAction((e) -&gt; {
          Double loanTotal = Double.parseDouble(loanAmount.getText());
          Integer year = Integer.parseInt(numYears.getText());
          Double rateInterest = Double.parseDouble(rate.getText());
          double monthlyInterest = rateInterest / 1200;
          double monthlyPayment = loanTotal * monthlyInterest / (1 - 1 / Math.pow(1 + monthlyInterest, year * 12));
          balance = loanTotal;
  
          for(int i = 1; i &lt; year * 12; i++) {
               interest = monthlyInterest * balance;
               principal = monthlyPayment - interest;
               balance = balance - principal;
               payment = i + 1;
          }
  
          ObservableList&lt;Finance&gt; data = FXCollections.observableArrayList(new Finance(payment, interest, principal, balance));
          table.setItems(data);
  
      });
  
  }
  
  public static class Finance {
      private final SimpleIntegerProperty payment;
      private final SimpleDoubleProperty interest;
      private final SimpleDoubleProperty principal;
      private final SimpleDoubleProperty balance;
  
      private Finance(int payment, double interest, double principal, double balance) {
          this.payment = new SimpleIntegerProperty(payment);
          this.interest = new SimpleDoubleProperty(interest);
          this.principal = new SimpleDoubleProperty(principal);
          this.balance = new SimpleDoubleProperty(balance);
      }
  
      public Integer getPayment(int numYears) {
          return payment.get();
      }
  
      public Double getInterest(double rate) {
  
          return interest.get();
      }
  
      public Double getPrincipal() {
          return principal.get();
      }
  
      public Double getBalance() {
          return balance.get();
      }
  }
  
  public static void main(String[] args) {
      launch(args);
  }
  
  }
  </code></pre>