- #1
iamjon.smith
- 117
- 3
Ok, Here is the assignment:
Develop a mortgage payment calculator. Design a GUI to enter price of home, down payment, interest rate. Your bank only offers 10, 15, and 30 year mortgages. Use grouped radio buttons to select between 10, 15, or 30 year mortgage. Monthly payment should be calculated by the application.
I have created the GUI with text field for Price of home (variable price), down payment (variable downPayment), and interest rate (variable interestRate).
I need to accept user input from the text boxes, calculate the mortgage, based on 10, 15, or 30 year mortgage that is dictated by a radio button.
I can't figure out what the next step I need is. Could someone take a look at the code and point me in the right direction. I have the Quit button working, but that is about it.
Develop a mortgage payment calculator. Design a GUI to enter price of home, down payment, interest rate. Your bank only offers 10, 15, and 30 year mortgages. Use grouped radio buttons to select between 10, 15, or 30 year mortgage. Monthly payment should be calculated by the application.
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* MortgagePaymentCalculator.java
*
* Created on Jan 26, 2011, 1:45:34 PM
*/
package my.calculator;
import javax.swing.JOptionPane;
import java.util.Scanner;
/**
*
* @author Jon and Jessica
*/
public class MortgagePaymentCalculator extends javax.swing.JFrame {
/** Creates new form MortgagePaymentCalculator */
public MortgagePaymentCalculator() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
price = new javax.swing.JTextField();
downPayment = new javax.swing.JTextField();
interestRate = new javax.swing.JTextField();
months1 = new javax.swing.JRadioButton();
months2 = new javax.swing.JRadioButton();
months3 = new javax.swing.JRadioButton();
jLabel5 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
monthlyPayment = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Mortgage Payment Calculator");
jLabel2.setText("Price of Home:");
jLabel3.setText("Down Payment:");
jLabel4.setText("Interest Rate:");
price.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
priceActionPerformed(evt);
}
});
downPayment.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
downPaymentActionPerformed(evt);
}
});
interestRate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
interestRateActionPerformed(evt);
}
});
buttonGroup1.add(months1);
months1.setText("10 Year Mortgage");
months1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
months1ActionPerformed(evt);
}
});
buttonGroup1.add(months2);
months2.setText("15 Year Mortgage");
months2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
months2ActionPerformed(evt);
}
});
buttonGroup1.add(months3);
months3.setText("30 Year Mortgage");
months3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
months3ActionPerformed(evt);
}
});
jLabel5.setText("Monthly Payment:");
jButton1.setText("Calculate Payment");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Quit");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel5)
.addComponent(jLabel4)
.addComponent(jLabel3)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(monthlyPayment, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(jLabel1)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(months3)
.addComponent(months2)
.addComponent(months1)
.addComponent(jButton2)))))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(price, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
.addComponent(downPayment, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(interestRate, javax.swing.GroupLayout.Alignment.LEADING)))
.addGap(146, 146, 146))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(months1)
.addGap(11, 11, 11)
.addComponent(months2)
.addGap(6, 6, 6)
.addComponent(months3))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(9, 9, 9)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(price, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(11, 11, 11)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(downPayment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(interestRate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))))
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(monthlyPayment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addGap(31, 31, 31))
);
pack();
}// </editor-fold>
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void priceActionPerformed(java.awt.event.ActionEvent evt) {
// User enters total price of home to be bought
Scanner input = new Scanner(System.in);
double price = input.nextDouble();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// On click of calculate button, the monthly payment is calculated
// and output to the monthly payment text box
double payment = 0;
monthlyPayment.setText(String.valueOf(payment));
}
private void downPaymentActionPerformed(java.awt.event.ActionEvent evt) {
// Accept user input for the amount of the down payment
// for calculating monthly payments
Scanner input = new Scanner(System.in);
double downPayment = input.nextDouble();
}
private void interestRateActionPerformed(java.awt.event.ActionEvent evt) {
// Accept user input for the amount of the interest rate for calculating monthly payment
Scanner input = new Scanner(System.in);
double interestRate = input.nextDouble();
}
private void months1ActionPerformed(java.awt.event.ActionEvent evt) {
// Calculate the interest based on a 10 year loan
int months = 120;
}
private void months2ActionPerformed(java.awt.event.ActionEvent evt) {
// Calculate the interest based on a 15 year loan
int months = 180;
}
private void months3ActionPerformed(java.awt.event.ActionEvent evt) {
// Calculate the interest based on a 30 year loan
int months = 360;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MortgagePaymentCalculator().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JTextField downPayment;
private javax.swing.JTextField interestRate;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JTextField monthlyPayment;
private javax.swing.JRadioButton months1;
private javax.swing.JRadioButton months2;
private javax.swing.JRadioButton months3;
private javax.swing.JTextField price;
// End of variables declaration
}
I have created the GUI with text field for Price of home (variable price), down payment (variable downPayment), and interest rate (variable interestRate).
I need to accept user input from the text boxes, calculate the mortgage, based on 10, 15, or 30 year mortgage that is dictated by a radio button.
I can't figure out what the next step I need is. Could someone take a look at the code and point me in the right direction. I have the Quit button working, but that is about it.