|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: |
/*
Author: Heather Miller
PRG421 Java Programming II
Date August 25, 2009
Instructor: Shriram Krishnan
Service Request SR-mf-003 Change Request #3
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.
*/
// declare of imports
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JFrame;
import java.text.NumberFormat;
import javax.swing.text.*;
import java.awt.Color;
public class MortCalcHM extends JFrame implements ActionListener{
// Labels
JLabel AmountLabel = new JLabel( "Enter Mortgage Amount " );
JLabel PaymentLabel = new JLabel( "Your Monthly Payment Is: " );
// Text Fields
JTextField mortgageAmount = new JTextField(10);
JTextField MonthlyPayment = new JTextField(10);
// Loan Buttons
JButton Loan1 = new JButton( "7 years at 5.35%" );
JButton Loan2 = new JButton( "15 years at 5.50%" );
JButton Loan3 = new JButton( "30 years at 5.75%" );
//Action Buttons
JButton ExitButton = new JButton( "Exit" );
JButton ClearButton = new JButton( "Clear" );
// Text Area and Scroll
JTextArea MortgageTable = new JTextArea(50,50);
JScrollPane scroll = new JScrollPane(MortgageTable);
{
//Frame, Panel, and Layout set up
setSize(600, 400);
setLocation(0, 0);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
//Grid Setup of Content
Container grid = getContentPane();
grid.setLayout(new GridLayout(6,2));
pane.add(grid);
pane.add(scroll);
grid.add(AmountLabel);
AmountLabel.setForeground(Color.BLUE);
grid.add(mortgageAmount);
grid.add(PaymentLabel);
PaymentLabel.setForeground(Color.BLUE);
grid.add(MonthlyPayment);
grid.add(Loan1);
Loan1.setForeground(Color.BLUE);
grid.add(Loan2);
Loan2.setForeground(Color.BLUE);
grid.add(Loan3);
Loan3.setForeground(Color.BLUE);
grid.add(ClearButton);
ClearButton.setForeground(Color.RED);
grid.add(ExitButton);
ExitButton.setBackground(Color.RED);
MonthlyPayment.setEditable(false);
setContentPane(pane);
setVisible(true);
//Adds Action Listeners
ExitButton.addActionListener(this);
ClearButton.addActionListener(this);
Loan1.addActionListener(this);
Loan2.addActionListener(this);
Loan3.addActionListener(this);
mortgageAmount.addActionListener(this);
MonthlyPayment.addActionListener(this);
}
public static void main(final String[] args) {
new MortCalcHM();
System.out.println("Mortgage Calculator Change Request #5");
}
public void actionPerformed(ActionEvent e)
{
Object command = e.getSource();
if
(
command == ExitButton)
System.exit(0);
//Array for Loans
int loanTerm = 0;
if (command == Loan1)
{
loanTerm = 0;
}
if (command == Loan2)
{
loanTerm = 1;
}
if (command == Loan3)
{
loanTerm = 2;
}
// Formula for Loan Calcualtions
double [][] loans = { {7, 5.35}, {15, 5.50}, {30, 5.75} };
double mortgage = 0; // Declares and Initializes mortgage
try{
mortgage = Double.parseDouble(mortgageAmount.getText());
}
catch(NumberFormatException numberformatexception)
{
JOptionPane.showMessageDialog(null, " Invalid Entry!\nPlease enter only numeric values!!", "ERROR", 0);
}
double interestRate = loans [loanTerm][1];
double intRate = (interestRate / 100) / 12;
double loanTermMonths = loans [loanTerm] [0];
int months = (int)loanTermMonths * 12;
double payment = mortgage * intRate / (1 - (Math.pow(1/(1 + intRate), months)));
double LoanBalance = mortgage;
double MonthlyPaymentInterest = 0;
double MonthlyPaymentPrincipal = 0;
// Number formatter to format output in table
NumberFormat cents = NumberFormat.getCurrencyInstance();
MonthlyPayment.setText(cents.format(payment));
MortgageTable.setText("Your Monthly Calcualation For The Term Of Loan\n"+
"Month\tPrincipal\tInterest\tEnding Balance\n" + // Formats the Mortgage Table
"----------\t------------\t-------------\t----------------------\n");
for (;months > 0 ; months -- )
{
//Append Mortgage Table
MonthlyPaymentInterest = (LoanBalance * intRate);//Monthly Payment Toward Interest
MonthlyPaymentPrincipal = (payment - MonthlyPaymentInterest);//Monthly Payment Toward Principal
LoanBalance = (LoanBalance - MonthlyPaymentPrincipal);//Remaining loan Balance
MortgageTable.setBackground(Color.LIGHT_GRAY);
MortgageTable.setForeground(Color.RED);
MortgageTable.setCaret (new DefaultCaret());
MortgageTable.append(String.valueOf(months) + "\t" +
cents.format(MonthlyPaymentPrincipal) + "\t" +
cents.format(MonthlyPaymentInterest) + "\t" +
cents.format(LoanBalance) + "\n");
}
//Clear Fields
if(command == ClearButton)
{
mortgageAmount.setText(null);
MonthlyPayment.setText(null);
MortgageTable.setText(null);
} }}
|
Advertisement
| Hall of Fame |