Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need help with pull down menu on mortage calculator!

843789Sep 18 2009 — edited Sep 18 2009
I need to set values for my pull down menu so that I am able to calculate the accurate amounts for this mortage calculator. The pull down works fine but whenever I would select the option it would display the results as "0". I am fairly new to Java programming so if anyone help me out I will greatly appreciate it! Thanks!By the way the assignment requires that I use arrays for the program.
/*
	Week3:		The McBride Gui Mortgage Calculator
	Programmer: S. Gutierrez
	Date:		September 13, 2009
	Filename:	MortGuiCalculator2.java
	Purpose:	This project calculates the monthly payments for McBride Mortgage
*/

import java.io.*;
import java.text.DecimalFormat;
import java.lang.Math;
import javax.swing.JOptionPane;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Date;
import java.text.*;

public class MortGuiCalculator3

{
    public static void main(String[] args)
    {
		// declare and construct variables
			 int numMonths,i,toggleInt;
			 int numYears=0;

			 double loantotal,paypermonth,newloantotal;
			 double annualint=0.0;
			 double monthint=0.0;

			 String totalLoanstring, interestLoanstring,decide,Loanterm;

			 int years[] = {7,15,30};    //Number of years in the loan
             double intRates[]={.0535,.055,.0575};   //Interest rate for the loan

             String sample[] = {"7 year at 5.35%","15 year at 5.5%","30 year at 5.75%"};


  	 //Decimal Formats
                DecimalFormat money = new DecimalFormat("$###,###,###,###.00");
                DecimalFormat percent = new DecimalFormat("#.00%");

     //Loop

           do {
                decide=JOptionPane.showInputDialog(null, "Press '1' to start the Mortgage Calculator or '0' to exit");
                toggleInt = Integer.parseInt(decide);

           if (toggleInt>0) {

			//Total amount borrowed
			totalLoanstring=JOptionPane.showInputDialog(null, "How much is the total loan amount?");
			loantotal = Double.parseDouble(totalLoanstring);

           switch (toggleInt) {
            case 1:

            String option = (String)JOptionPane.showInputDialog(null,"Which loan option?","Options",JOptionPane.QUESTION_MESSAGE,null,sample,sample[sample.length-1]);
           //Total number of years of the loan

           break;

   }

   		monthint=annualint/12;  //The monthly interest rate of the loan
   		numMonths = numYears*12;                    //Number of months
   		paypermonth=loantotal*(monthint/(1-(Math.pow((1+monthint),0-numMonths))));    //The monthly payment

   		//Output Monthly Payment
   		JOptionPane.showMessageDialog(null,"Your loan of " + money.format(loantotal) + " for " + numYears +" years \nat an annual interest rate of " + percent.format(annualint) + "\nwill cost you " + money.format(paypermonth) + " a month for the life of the loan.\n\nPlease click OK to return to the main menu.","McBride Financial Services Mortage Calculator",JOptionPane.INFORMATION_MESSAGE);
;
                       }

           } while (toggleInt>0);
           System.exit(0);
       }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 16 2009
Added on Sep 18 2009
1 comment
110 views