Results 1 to 6 of 6
- 08-17-2009, 03:46 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 3
- Rep Power
- 0
help capturing input from drop down
Working on an assignment and just need a little help or point in the right direction to capture the information in the drop down. I was able to capture the text if it is manually entered but using the drop down is messing with me. I can either use a drop down or select the 3 options from check boxes.
Java Code:import java.io.*; import java.awt.*; import java.text.DecimalFormat; //import java.text for decimal formatting import java.lang.Math; //import java math class for formulas and calculations import javax.swing.JOptionPane; //import a Java swing components for display messages and accept user input via dialog boxes public class Mortgage_Calc { public static void main(String[] args) //method header { //declare variables int numMonths,iVar,iMenuInt; int numYears=0; int years[] = {7,15,30}; //static number of years double intRates[]={.0535,.055,.0575}; //static interest rates double loanAmount,monthlyPayment,newloanAmount,curMInterest,curMPrincipal; double annualInterestRate=0.0; double monthInterestRate=0.0; String totalLoan,interestLoan,pmtSched,iMenu,termLoan; String sample[] = {"7 years at 5.35%","15 years at 5.5%","30 years at 5.75%"}; //set decimal formats DecimalFormat money = new DecimalFormat("$###,###.00"); DecimalFormat percent = new DecimalFormat("#.00%"); //start loop do { iMenu=JOptionPane.showInputDialog(null, "Option 0 - Exit program.\nOption 1 - To input amount, then select a predetermined term, and interest rate.\n\nenter 1 to run program or O (zero) to quit"); iMenuInt = Integer.parseInt(iMenu); if (iMenuInt>0) { //ask for loan amount totalLoan=JOptionPane.showInputDialog(null, "What is the amount of the mortgage?\n\nexample ($200,000 = 200000) do not enter , or $"); loanAmount = Double.parseDouble(totalLoan); switch (iMenuInt) { case 1: //display dropdown selection String option = (String)JOptionPane.showInputDialog(null,"Which loan option?","Options",JOptionPane.QUESTION_MESSAGE,null,sample,sample[sample.length-1]); break; } monthInterestRate=annualInterestRate/12; //interest rate broken down by month numMonths = numYears*12; //converts years to months monthlyPayment=loanAmount*(monthInterestRate/(1-(Math.pow((1+monthInterestRate),0-numMonths)))); //monthly payment formula //monthly payment output JOptionPane.showMessageDialog(null,"A mortgage loan of " + money.format(loanAmount) + " for " + numYears +" years \nwith an interest rate of " + percent.format(annualInterestRate) + " will result in a\nmonthly payment of " + money.format(monthlyPayment) + " for the life of the loan.\n\nPlease click OK to see the amortization schedule.","Thank you!",JOptionPane.INFORMATION_MESSAGE); //amortization output iVar=0; pmtSched="\nMonth "; pmtSched+="Balance "; pmtSched+="Interest "; pmtSched+="Principal\n"; do { iVar++; curMInterest=loanAmount*monthInterestRate; //payment that is applied to the interest on the loan curMPrincipal=monthlyPayment-curMInterest; //payment that is applied to the principal of the loan newloanAmount=loanAmount-curMPrincipal; //remaining balance of the loan at the end of the month pmtSched+=String.valueOf(iVar)+" "; pmtSched+=money.format(loanAmount)+" "; pmtSched+=money.format(curMInterest)+" "; pmtSched+=money.format(curMPrincipal)+"\n"; loanAmount=newloanAmount; if ( iVar % 25 == 0) { pmtSched+="\n\n\nMonth "; pmtSched+="Balance "; pmtSched+="Interest "; pmtSched+="Principal\n"; } } while (iVar<numMonths); JOptionPane.showMessageDialog(null,new TextArea(pmtSched,30,60),"Your Loan Payment Amortization Schedule",JOptionPane.INFORMATION_MESSAGE); } } while (iMenuInt>0); System.exit(0); } }Last edited by javalearner1234; 08-17-2009 at 03:49 AM.
- 08-17-2009, 03:56 AM #2
-
Your JOptionPane.showInputDialog returns a String. Have you had a look at the String returned? If not, you should...
Java Code:switch (iMenuInt) { case 1: // display dropdown selection String option = (String) JOptionPane.showInputDialog(null, "Which loan option?", "Options", JOptionPane.QUESTION_MESSAGE, null, sample, sample[sample.length - 1]); // !! I added this. See what's returned. Perhaps you can use it. System.out.println("Option selected: " + option); break; }
- 08-17-2009, 04:10 AM #4
Member
- Join Date
- Aug 2009
- Posts
- 3
- Rep Power
- 0
Thanks fubarable-- I added your line and it did not help. I am thinking I am going to have to start over on this. My last assignment just wanted everything manually entered, which worked. So I was just trying to tweak that program to work from a drop down. The 3rd assignement just combines both of these options so that is easier if I can get past this.
thanks again
-
My line was not a direct solution to your problem but to allow you to see what that String held. If you know what the String holds, you should be smart enough to compare it with the source Strings in the sample array and thereby come up with a solution, no?Thanks fubarable-- I added your line and it did not help.
- 08-17-2009, 05:00 AM #6
Member
- Join Date
- Aug 2009
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
dynamically changing drop down box on selection in first drop down
By anjali in forum Advanced JavaReplies: 1Last Post: 04-01-2009, 10:28 AM -
passively and quickly capturing request/response
By sideswipe091976 in forum NetworkingReplies: 1Last Post: 07-10-2008, 01:01 AM -
Capturing video with Robot
By russ2620 in forum AWT / SwingReplies: 0Last Post: 06-03-2008, 04:49 PM -
Capturing Groups using regular expressions
By Java Tip in forum Java TipReplies: 0Last Post: 12-25-2007, 11:19 AM -
MAC address capturing
By viswa.tk in forum Java AppletsReplies: 0Last Post: 12-13-2007, 08:36 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks