Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help with Java Mortgage Program

807603Jan 9 2008 — edited Jan 9 2008
Hi everyone I am new here and this is my first thread. I am having trouble getting this GUI program to run. I am wondering If I coded this too much like an applet instead of a GUI. Is Gui code and applet code the same? I want this to run as a standalone program. My code compiles correctly but I keep getting the message : "Exception in the thread "main java.lang.NoSuchMethod Error: main".

I have no idea what I am doing wrong. I am hoping that someone can give me some insight. Here is my code :


import java.text.NumberFormat;
import java.util.Locale;
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
//import java.text.NumberFormat;
//import java.util.Locale;



public class TAMortgage extends JApplet implements ActionListener {

NumberFormat moneyFormat = NumberFormat.getCurrencyInstance( Locale.US );


//double aryAmounts= 0;
double Rates= 0; //basic loan variables (for use with radio buttons)
double Terms = 0; //basic loan variables(for use with radio buttons)
double rate = 0; //basic loan variables
double amount = 0; //basic loan variables
double term = 0; //basic loan variables
int i = 0;
int button = 0;
int l = 0;
int lStack = 361;//for dyanamic array size
int amtTrk = 1;

private static final long serialVersionUID = 1L;//elcipse suggested line



JPanel Panel = new JPanel();
JTextArea display = new JTextArea(17, 42);
JScrollPane scrollPane = new JScrollPane(display, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JPanel title = new JPanel();
JPanel outputPanel = new JPanel();
JTextField t = new JTextField(10);
JLabel Label = new JLabel("Mortgage Amorization Calculator\n");
JLabel loanLabel = new JLabel("Select loan type:");
JLabel rbInstruct = new JLabel("Please enter mortgage amount");
JLabel rbInstruct2 = new JLabel("(no commas or dollar signs)");
ButtonGroup radio = new ButtonGroup();
JRadioButton rate1 = new JRadioButton("7 years @ 5.35%", true);
JRadioButton rate2 = new JRadioButton("15 years @ 5.5%", false);
JRadioButton rate3 = new JRadioButton("30 years @ 5.75%", false);
JRadioButton Custom = new JRadioButton("Custom Terms/Rate");
JButton Term = new JButton("Term in years");
JButton Rate = new JButton("Interest Rate");
JButton calcButton = new JButton("Calculate!");

public void init()
{
display.setEditable(false);
Container input = getContentPane();
setSize(new Dimension(750, 290));
input.setLayout(new FlowLayout(FlowLayout.CENTER));
radio.add(rate1);
radio.add(rate2);
radio.add(rate3);
radio.add(Custom);
Panel.setLayout(new GridLayout(10,1));

//add panels to container
input.add(Panel);
Panel.add(Label);
Panel.add(rbInstruct);
Panel.add(rbInstruct2);
Panel.add(t);
Panel.add(loanLabel);
Panel.add(rate1);
Panel.add(rate2);
Panel.add(rate3);
Panel.add(Custom);
Panel.add(calcButton);

input.add(outputPanel);
outputPanel.add(scrollPane);

//Listeners
rate1.addActionListener(this);
rate2.addActionListener(this);
rate3.addActionListener(this);
Custom.addActionListener(this);
t.addActionListener(this);
calcButton.addActionListener(this);

}
public class Mortgage {

private double payment;
private double H;
private double C;
private double Q;
private double interest;



public void setPayment ( double amount, double term, double rate) {
double J = (rate/(12*100));
double N = (term*12);
this.payment = (amount * J/(1 - Math.pow((1+J),-N)));
}

public double getPayment(){
return payment;
}

public void setH(double newamount, double interest) {
this.H = (newamount * interest);
}

public double getH(){
return H;
}

public void setC(double payamount, double H) {
this.C = (payamount - H);
}

public double getC(){
return C;
}

public void setQ(double newamount, double C) {
this.Q = (newamount - C);
}

public double getQ(){
return Q;
}

public void setInterest(double rate) {
this.interest = (rate /(12*100));
}

public double getInterest(){
return interest;
}

}

//applet start
public void start()
{

repaint();
}



//event driven actions
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();


String response = t.getText();
//t.append(text + newline);
t.selectAll();

double Amount = Double.parseDouble(response);


if ( rate1.isSelected() )
{
display.setText("");
Rates = 5.35;
Terms = 7;
}

if ( rate2.isSelected() )
{
display.setText("");
Rates = 5.5;
Terms = 15;
}

if ( rate3.isSelected() )
{
display.setText("");
Rates = 5.75;
Terms = 30;
}

if ( Custom.isSelected() )
{
display.setText("");
String response1 = JOptionPane.showInputDialog(null, "Enter the mortgage term");
Terms = Integer.parseInt(response1);
lStack = (int) (lStack + (Terms*12));
String response2 = JOptionPane.showInputDialog(null, "Enter the mortgage interest rate");
Rates = Double.parseDouble(response2);
source = calcButton;
}


if(source == calcButton)
{





display.setText("");

double [] H = new double[lStack];
double [] C = new double[lStack];
double [] Q = new double[lStack];
double [] newamount = new double[lStack];

rate = Rates;
amount = Amount;
term = Terms;
//double amount = aryAmounts;
Mortgage m = new Mortgage();
m.setPayment(amount, term, rate);
//System.out.println(m.getPayment()); Troubleshooting line


m.setInterest(rate);


display.append("\t The mortgage amount is " + moneyFormat.format(amount)+ "\n");
display.append("\t The mortgage term is " + term + " years"+ "\n");
display.append("\t The mortgage rate is " + rate + " percent"+ "\n");

double payamount = m.getPayment();

display.append("\t The monthly payment is: " + moneyFormat.format(payamount)+ "\n");
display.append("*******************************************************************************************\n");
int track = 0;

newamount[amtTrk] = amount; //variables initialized to work with Mortgage class
double interest = m.getInterest();//variables initialized to work with Mortgage class
display.append("Pmt #" + "\tPrevious Bal." + "\tInterest paid" + "\tPrinciple paid" + "\tBalance\n");



int ticker = 0;
while (newamount[amtTrk] > payamount)//amortization while loop
{
++track;


m.setH(newamount[amtTrk], interest);
H[track] = m.getH();
m.setC(payamount, H[track]);
C[track] = m.getC();
m.setQ(newamount[amtTrk], C[track]);
Q[track] = m.getQ();
display.append(track + "\t" + moneyFormat.format(newamount[amtTrk]) + "\t" + moneyFormat.format(H[track]) + "\t" + moneyFormat.format(C[track]) + "\t" + moneyFormat.format(Q[track])+ "\n");
++amtTrk;
newamount[amtTrk] = Q[track];
++ticker;
}

++track;
//newamount = m.getQ();
m.setH(newamount[amtTrk], interest);
H[track] = m.getH();
m.setC(payamount, H[track]);
C[track] = m.getC();
m.setQ(newamount[amtTrk], C[track]);
Q[track] = m.getQ();
//System.out.println(track + "\t" + moneyFormat.format(newamount[amtTrk]) + "\t" + moneyFormat.format(H[track]) + "\t\t" + moneyFormat.format(C[track]) + "\t\t" + moneyFormat.format(Q[track])+ "\n");
display.append(track + "\t" + moneyFormat.format(newamount[amtTrk]) + "\t" + moneyFormat.format(H[track]) + "\t" + moneyFormat.format(C[track]) + "\t" + moneyFormat.format(Q[track])+ "\n");
display.append("*******************************************************************************************\n");
display.append(" Please scroll up to see amount, term, rate, and payment information.\n");
display.append("*******************************************************************************************\n");
display.append("To amoritize a new loan, please adjust loan details as necessary and hit 'Calculate'.\n");
display.append("=================================================================");
int newlStack = lStack + track;
lStack = newlStack;


}
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 6 2008
Added on Jan 9 2008
7 comments
151 views