# Help With GUI Mortgage Calculator

• 10-29-2006, 11:06 PM
drewdat7001
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
//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);
//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);
//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.
• 10-29-2006, 11:34 PM
nspils
"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?