This is the assignment:
Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage and the user's selection from a menu of available mortgage loans:

- 7 years at 5.35%
- 15 years at 5.5%
- 30 years at 5.75%

Use an array for the mortgage data for the different loans. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. Allow the user to loop back and enter a new amount and make a new selection or quit. Please insert comments in the program to document the program.
Here is my code. It will compile with no errors, it will run but, there are panels missing and it will not calculate. I have tried adding panels, fields, different formulas. Nothing works. I need to turn it in tommorow night by 11:59PM MST, USA. Can anyone tell me where I am messing up?

*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;


class mortgageGUI3 extends JFrame implements ActionListener // inheritance
{
static DecimalFormat decmat = new DecimalFormat("$#,##0.00");
FlowLayout flow = new FlowLayout();
JLabel amount1 = new JLabel("Amount: ");
JTextField amount = new JTextField(10);
JLabel rate1 = new JLabel("Rate: ");
JTextField rate = new JTextField(4);
JLabel term1 = new JLabel("Term: ");
JTextField term = new JTextField(4);
JComboBox mortgageBox = new JComboBox();
JLabel mortgageList = new JLabel("Choose the Mortgage Loans");
JButton calcButton = new JButton("Calculate Total");
JButton exitButton = new JButton("Exit");
JButton reset = new JButton("Reset");
JLabel blankSpaces1 = new JLabel(" ");
JLabel blankSpaces2 = new JLabel(" ");
JLabel result = new JLabel("The total is:");
JLabel sum = new JLabel("");

public mortgageGUI3()
{
Container con = getContentPane();

con.setLayout(flow); // places components in a row
con.add(amount1);
con.add(amount);
con.add(rate1);
con.add(rate);
con.add(term1);
con.add(term);
con.add(calcButton);
con.add(blankSpaces1);
con.add(result);
con.add(sum);
mortgageBox.addItem("The Mortgage Inputs Above");
mortgageBox.addItem(" 7-year Mortgage at 5.35%"); //terms
mortgageBox.addItem("15-year Mortgage at 5.5%");
mortgageBox.addItem("30-year Mortgage at 5.75%");
con.add(blankSpaces2);
con.add(exitButton);
con.add(reset);
con.add(mortgageList);
con.add(mortgageBox);


amount.setBackground(Color.yellow); // setting the background to make it attractive
rate.setBackground(Color.yellow);
term.setBackground(Color.yellow);
calcButton.setForeground(Color.black);
calcButton.setBackground(Color.yellow);

exitButton.setForeground(Color.black);
exitButton.setBackground(Color.yellow);

reset.setForeground(Color.black);
reset.setBackground(Color.yellow);

mortgageBox.addActionListener(this);
mortgageBox.setForeground(Color.white);
mortgageBox.setBackground(Color.black);

con.setBackground(Color.white); //sets the background color

calcButton.addActionListener(this);
exitButton.addActionListener(this);
reset.addActionListener(this);
}
public static void main(String[] args) // main program
{
mortgageGUI3 cFrame = new mortgageGUI3();
cFrame.setTitle("McBride's Mortgage Calculator");
cFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cFrame.setSize(300,300);
cFrame.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
Object resetButton = null;
if(source == calcButton)
{
try // exception handling
{
String amt = amount.getText();
String trm = term.getText();
String rte = rate.getText();
double a1 = Double.parseDouble(amt);
double r1 = Double.parseDouble(rte);
if(r1 == 0) getCleanScreen();
double t1 = Double.parseDouble(trm);
if(t1 == 0) getCleanScreen();

java.text.DecimalFormat dec = new java.text.DecimalFormat(",##0.00");
java.text.DecimalFormat doldec = new java.text.DecimalFormat("$,##0.00");

double mortgagefigure = getPayment(a1, r1, t1, 12);
double total = getFigure(mortgagefigure);
String output = "" + doldec.format(total);

sum.setText(""+output+"");
}
catch (NumberFormatException error)
{
getCleanScreen();
}
}
else if (source == mortgageBox)
{
int sizeNum = mortgageBox.getSelectedIndex();
if (sizeNum == 0)
try
{
getCleanScreen();
}
catch (NumberFormatException error)
{
getCleanScreen();
}
else if (sizeNum == 1)
{
try
{
String amt = amount.getText();
double a1 = Double.parseDouble(amt);
double r1 = 7;
double t1 = 5.35;

java.text.DecimalFormat dec = new java.text.DecimalFormat(",##0.00");
java.text.DecimalFormat doldec = new java.text.DecimalFormat("$,##0.00");

double mortgagefigure = getPayment(a1, r1, t1, 12);
double total = getFigure(mortgagefigure);
String output = "" + doldec.format(total);

rate.setText("");
term.setText("");
sum.setText(""+output+"");
}
catch (NumberFormatException error)
{
getCleanScreen();
}
}
else if (sizeNum == 2)
{
try
{
String amt = amount.getText();
double a1 = Double.parseDouble(amt);
double r1 = 15;
double t1 = 5.5;

java.text.DecimalFormat dec = new java.text.DecimalFormat(",##0.00");
java.text.DecimalFormat doldec = new java.text.DecimalFormat("$,##0.00");

double mortgagefigure = getPayment(a1, r1, t1, 12);
double total = getFigure(mortgagefigure);
String output = "" + doldec.format(total);

rate.setText("");
term.setText("");
sum.setText(""+output+"");
}
catch (NumberFormatException error)
{
getCleanScreen();
}
}
else
{
try
{
String amt = amount.getText();
double a1 = Double.parseDouble(amt);
double r1 = 30;
double t1 = 5.75;

java.text.DecimalFormat dec = new java.text.DecimalFormat(",##0.00");
java.text.DecimalFormat doldec = new java.text.DecimalFormat("$,##0.00");

double mortgagefigure = getPayment(a1, r1, t1, 12);
double total = getFigure(mortgagefigure);
String output = "" + doldec.format(total);

rate.setText("");
term.setText("");
sum.setText(""+output+"");
}
catch (NumberFormatException error)
{
getCleanScreen();
}
}
}
else if(source == resetButton)
{
getCleanScreen();
}
else
{

System.exit(0);
}
}// end actionPerformed
private void getCleanScreen() {
throw new UnsupportedOperationException("Not yet implemented");
}

private double getFigure(double mortgagefigure) {
throw new UnsupportedOperationException("Not yet implemented");
}

private double getPayment(double a1, double r1, double t1, int i) {
throw new UnsupportedOperationException("Not yet implemented");
}
}

Please edit your posted code and add code tags (upper right icon/link above this text field)
to preserve the formatting.

Nothing works

That'll make it hard to help.
Can you ask specific questions about your problem?

Edited 6 Years Ago by NormR1: n/a

This is not a mortgage calculator with a GUI, this is a GUI that calculates mortgages. Consider yourself grumbled at.

Now, it doesn't calculate, you say?

private void getCleanScreen() {
throw new UnsupportedOperationException("Not yet implemented");
}

private double getFigure(double mortgagefigure) {
throw new UnsupportedOperationException("Not yet implemented");
}

private double getPayment(double a1, double r1, double t1, int i) {
throw new UnsupportedOperationException("Not yet implemented");
}

Could it be that you haven't implemented your getPayment method? Just guessing.

This article has been dead for over six months. Start a new discussion instead.