-
Help With GUI Mortgage Calculator
I'm working on a program (with a graphical user interface) that will calculate and display the mortgage payment amount, the loan balance, loan payment number, and interest paid from each payment from these three loans below:
7 years at 5.35%
15 years at 5.5%
30 years at 5.75%
The problem that I'm having when I compile my code I'm getting these three errors:
orphaned case line 52
orphaned case line 79
orphaned default line 106
Here is my source code:
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class MortgageCalculatorServiceRequest5///Name of my File and Class
{
public static void main(String[] args)
{
double monthlyPayment;//Declaring my Variables
int loanNumber;
String totalLoan;
int loanAmount;
double loanInterest;
int loanTerm;
DecimalFormat decimalPlaces=new DecimalFormat("0.00"); //Format decimal point for proper display
totalLoan=JOptionPane.showInputDialog(null, "Enter the number of What Loan You would like to see broken down by\n mortgage payment amount followed by the loan balance and interest paid for each payment:\n 1. 7 years at 5.35%:\n 2. 15 years at 5.5%:\n 3. 30 years at 5.75%\n ");
loanNumber = Integer.parseInt(totalLoan);
switch (loanNumber)
{
case 1:
loanAmount = 200000;
loanInterest = .0535;
loanTerm = 7;
monthlyPayment = (loanAmount*(loanInterest/12))/(1-(Math.pow(1/(1+(loanInterest/12)),(loanTerm*12))));//Math formula for Mortgage Monthly Payment
JOptionPane.showMessageDialog(null,"Your Monthly Payments Are" +decimalPlaces.format(monthlyPayment)+JOptionPane.PLAIN_MESSAGE);
//determine loan balance
double mintamount; //Variable - Holder for amount of Interest paid in a given month
double loanBalance; //Variable - New loan balance after monthly payment
double prinPayment; //Variable - Holder for principle payment each month
double monthintamount;
double mintAmount;
prinPayment = monthlyPayment-loanInterest;
loanBalance = loanAmount - prinPayment;
mintAmount = monthlyPayment-prinPayment;
monthintamount = loanInterest*loanAmount;
loanBalance = loanAmount - mintAmount;
int monthpay = 1;
int mPaynumber = 0;
//Begins Looping for each payment amount
while (loanBalance > 0) {
JOptionPane.showMessageDialog(null,"Payment Number" +decimalPlaces.format(mPaynumber)+JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null,"The new balance is: $" +decimalPlaces.format(loanBalance)+JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null,"The interest paid on the loan is: $" +decimalPlaces.format(monthintamount)+JOptionPane.PLAIN_MESSAGE);
loanBalance = loanBalance - prinPayment;
monthintamount = (loanBalance * (loanInterest/ 12)); //formula determines monthly interest paid
break;
case 2:
loanAmount = 200000;
loanInterest = .055;
loanTerm = 15;
monthlyPayment = (loanAmount*(loanInterest/12))/(1-(Math.pow(1/(1+(loanInterest/12)),(loanTerm*12))));//Math formula for Mortgage Monthly Payment JOptionPane.showMessageDialog(null,"Your Monthly Payments Are" +decimalPlaces.format(monthlyPayment)+JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null,"Your Monthly Payments Are" +decimalPlaces.format(monthlyPayment)+JOptionPane.PLAIN_MESSAGE);
//determine loan balance
double mintamount; //Variable - Holder for amount of Interest paid in a given month
double loanBalance; //Variable - New loan balance after monthly payment
double prinPayment; //Variable - Holder for principle payment each month
double monthintamount;
double mintAmount;
prinPayment = monthlyPayment-loanInterest;
loanBalance = loanAmount - prinPayment;
mintAmount = monthlyPayment-prinPayment;
monthintamount = loanInterest*loanAmount;
loanBalance = loanAmount - mintAmount;
int monthpay = 1;
int mPaynumber = 0;
//Begins Looping for each payment amount
while (loanBalance > 0) {
JOptionPane.showMessageDialog(null,"Payment Number" +decimalPlaces.format(mPaynumber)+JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null,"The new balance is: $" +decimalPlaces.format(loanBalance)+JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null,"The interest paid on the loan is: $" +decimalPlaces.format(monthintamount)+JOptionPane.PLAIN_MESSAGE);
loanBalance = loanBalance - prinPayment;
monthintamount = (loanBalance * (loanInterest/ 12)); //formula determines monthly interest paid
break;
case 3:
loanAmount = 200000;
loanInterest = .0575;
loanTerm = 30;
monthlyPayment = (loanAmount*(loanInterest/12))/(1-(Math.pow(1/(1+(loanInterest/12)),(loanTerm*12))));//Math formula for Mortgage Monthly Payment JOptionPane.showMessageDialog(null,"Your Monthly Payments Are" +decimalPlaces.format(monthlyPayment)+JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null,"Your Monthly Payments Are" +decimalPlaces.format(monthlyPayment)+JOptionPane.PLAIN_MESSAGE);
//determine loan balance
double mintamount; //Variable - Holder for amount of Interest paid in a given month
double loanBalance; //Variable - New loan balance after monthly payment
double prinPayment; //Variable - Holder for principle payment each month
double monthintamount;
double mintAmount;
prinPayment = monthlyPayment-loanInterest;
loanBalance = loanAmount - prinPayment;
mintAmount = monthlyPayment-prinPayment;
monthintamount = loanInterest*loanAmount;
loanBalance = loanAmount - mintAmount;
int monthpay = 1;
int mPaynumber = 0;
//Begins Looping for each payment amount
while (loanBalance > 0) {
JOptionPane.showMessageDialog(null,"Payment Number" +decimalPlaces.format(mPaynumber)+JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null,"The new balance is: $" +decimalPlaces.format(loanBalance)+JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null,"The interest paid on the loan is: $" +decimalPlaces.format(monthintamount)+JOptionPane.PLAIN_MESSAGE);
loanBalance = loanBalance - prinPayment;
monthintamount = (loanBalance * (loanInterest/ 12)); //formula determines monthly interest paid
break;
default:
JOptionPane.showMessageDialog(null,"Please enter 1, 2, or 3"+JOptionPane.PLAIN_MESSAGE);
}
System.exit(0);
}}}}}
I have bolded the source code that has errors. Any help on this would be much appreciated.
-
"Orphaned" case calls are the result of the compiler's decision that it will be impossible to reach these cases because of the code's establishment of the condition(s) of the value which will be the case value. There is a reason - I cannot find it yet - that the compiler decides that your switch will ALWAYS choose case 1 and CANNOT choose the other cases, including the default case.
Do you have a pre-determined output or choice value for your JOptionPane? Is that default choice 1?
Shouldn't you be assigning a value to totalLoan by using the your JOptionPane's getInputValue method?
Similar Threads
-
By Richbezza in forum C++
Replies: 3
Last Post: 05-09-2007, 02:16 AM
-
By drewdat7001 in forum Java
Replies: 4
Last Post: 12-20-2006, 12:55 AM
-
Replies: 1
Last Post: 09-26-2005, 05:09 PM
-
Replies: 7
Last Post: 09-06-2005, 05:06 PM
-
By phamber in forum ASP.NET
Replies: 1
Last Post: 07-22-2005, 08:55 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks