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);
}
}
Pull Down menu in JavaAdding values in pull down menu in Java
Page 1 of 1
4 Replies - 644 Views - Last Post: 19 September 2009 - 12:31 PM
#1
Pull Down menu in Java
Posted 18 September 2009 - 04:06 PM
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.
Replies To: Pull Down menu in Java
#2
Re: Pull Down menu in Java
Posted 18 September 2009 - 04:24 PM
First of all, annualint and numYears are set to 0.0 at the starting, but never changed throughout the code. After you set the String option, you should check what its contents are equal to, then set annualint and numYears as the corresponding numbers from the years[] and intRates[] arrays.
Like this:
Like this:
String option = (String)JOptionPane.showInputDialog(null,"Which loan option?","Options",JOptionPane.QUESTION_MESSAGE,null,sample,sample[sample.length-1]);
if (option.equals("7 year at 5.35%"))
{
numYears = years[0];
annualint = intRates[0];
}
if (option.equals("15 year at 5.5%"))
{ //etc.
This post has been edited by Overachiever: 18 September 2009 - 04:27 PM
#3
Re: Pull Down menu in Java
Posted 18 September 2009 - 07:09 PM
What do you call a "pull down menu" ?
#4
Re: Pull Down menu in Java
Posted 19 September 2009 - 12:22 PM
I think maybe a JComboBox?
#5
Re: Pull Down menu in Java
Posted 19 September 2009 - 12:31 PM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|