Help With GUI Mortgage Calculator


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Help With GUI Mortgage Calculator

  1. #1
    Join Date
    Oct 2006
    Posts
    3

    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.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    "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

  1. Mortgage Calculator Help Requested
    By Richbezza in forum C++
    Replies: 3
    Last Post: 05-09-2007, 03:16 AM
  2. Code Help with GUI Mortgage Calculator
    By drewdat7001 in forum Java
    Replies: 4
    Last Post: 12-20-2006, 01:55 AM
  3. Mortgage calculator help
    By vwrado in forum Java
    Replies: 1
    Last Post: 09-26-2005, 06:09 PM
  4. Mortgage Calculator Help
    By vwrado in forum Java
    Replies: 7
    Last Post: 09-06-2005, 06:06 PM
  5. Mortgage Calculator
    By phamber in forum ASP.NET
    Replies: 1
    Last Post: 07-22-2005, 09: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center