[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.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

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!

8.7

exception

Asked by hmmiller1 in Java Programming Language

Tags: java

I am having trouble with my exception. It still runs that calculation if they enter in a letter or if they click a button without entering in a mortgage amount.
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);
 
 
} }}
 
Related Solutions
 
Loading Advertisement...
 
[+][-]09/15/09 01:28 AM, ID: 25332869Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Java Programming Language
Tags: java
Sign Up Now!
Solution Provided By: CEHJ
Participating Experts: 1
Solution Grade: A
 
[+][-]09/14/09 02:40 PM, ID: 25329601Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 02:43 PM, ID: 25329621Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 02:49 PM, ID: 25329668Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 02:51 PM, ID: 25329685Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 03:03 PM, ID: 25329765Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 03:09 PM, ID: 25329805Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 03:10 PM, ID: 25329811Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 03:27 PM, ID: 25329905Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 03:30 PM, ID: 25329917Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 03:40 PM, ID: 25329979Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 03:52 PM, ID: 25330027Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/09 10:04 AM, ID: 25742031Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625