Pull Down menu in Java

Adding values in pull down menu in Java

Page 1 of 1

4 Replies - 975 Views - Last Post: 19 September 2009 - 12:31 PM Rate Topic: -----

#1 SteventheBerean  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-September 09

Pull Down menu in Java

Post icon  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.



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);
	   }
}




Is This A Good Question/Topic? 0
  • +

Replies To: Pull Down menu in Java

#2 Overachiever  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 36
  • Joined: 09-September 09

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:
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

Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Pull Down menu in Java

Posted 18 September 2009 - 07:09 PM

What do you call a "pull down menu" ?
Was This Post Helpful? 0
  • +
  • -

#4 ts230  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 225
  • Joined: 11-July 09

Re: Pull Down menu in Java

Posted 19 September 2009 - 12:22 PM

I think maybe a JComboBox?
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Pull Down menu in Java

Posted 19 September 2009 - 12:31 PM

View Postts230, on 19 Sep, 2009 - 11:22 AM, said:

I think maybe a JComboBox?

Don't see any ComboBox in that code
and Steven said in his original post "The pull down works fine"
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1