Page 1 of 2 12 LastLast
Results 1 to 20 of 32
Like Tree3Likes

Thread: Cant get this multi-option box to work :(

  1. #1
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default Cant get this multi-option box to work :(

    I cant seem to get this to work.. Any pointers?


    Java Code:
      Object[] options= {"Show Amortization","Enter Another Loan","Exit Program"};
         }
        a=JOptionPane.showConfirmDialog(null, "Would you like to see the amortization of the current loan?");
        JOptionPane.YES_NO_CANCEL_OPTION;
        JOptionPane.Question_MESSAGE;
    
        if("Show Amortization"==yes{contniue};
    
    
    
    
        else if("Enter Another Loan"==no){main();
        return;}
        else if ("Exit Prgram");{System.exit(0)
        };

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    I cant seem to get this to work.. Any pointers?
    Java Code:
     if("Show Amortization"==yes{contniue};
    This single statement has almost too many errors:
    Comparing Strings with ==
    No ending ) for the condition
    continue misspelled

    I'll leave the rest for the next guy. This is too easy.

  3. #3
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default

    yea i have no idea whats going on with this.... is there even a way to go back to the top of a program or keep going with the rest of the program?

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    is there even a way to go back to the top of a program
    The code you posted will not compile. Until it compiles, it will not go anywhere.

    Use a loop to allow execution to go back to an earlier point in the program.

  5. #5
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default

    how would a loop start over a program? every thing i have read on loops and if statements dont seem to work.. Do i start the loop at the beginning of the program? then once i get to where i want it to continue or start over add the string?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    Loops don't start a program. They are used allow you to repeatedly execute a group of statements.
    In pseudo code:
    Java Code:
    begin loop
      do some stuff
      if (...) continue;  // go back to the beginning of the loop
      do some more stuff
     // at this point the execution goes back to the top of of the loop (or it can test a condition and exit the loop)
    end loop

  7. #7
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default

    damn.. im still drawing a blank.... this seems to hard of a acquirement for only doing java for about a week or so... I dont even know where to start.

    in order to start a loop do i have to declare and int value, or have a statement that allows it to count?

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    to start a loop do i have to
    Depends on what kind of loop. There are more than one.
    You need to find a tutorial that describes how to write a java program, including loops.

  9. #9
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default

    Ok so i have read and read and watch videos... Still not fully understanding this... With the code below i am getting these exceptions:
    continue outside of loop;
    cannot find symbol method ConfirmOption(<nulltype>,java.lang.String,int);

    Am i close?



    Java Code:
    cont=JOptionPane.ConfirmOption(null,"Would you like to see the amoritization of current loan?",
         JOptionPane.YES_NO_OPTION);
          if(cont.equals(true))
          {continue;}

  10. #10
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default

    And do i place it inside the amortization loop like this?

    Java Code:
    //below is the loop
       p=1;
      balance=loan;
      
      for(int month=0;month<(years*12);month++)
    
    cont=JOptionPane.ConfirmOption(null,"Would you like to see the amoritization of current loan?",
         JOptionPane.YES_NO_OPTION);
          if(cont.equals(true))
          {continue;}
         else(JOptionPane.)
    
      {
      	interest=balance*interest_mo;
      //System.out.println("interest "+interest);
    
      principal=payments-interest;
      //System.out.println("principal "+ principal);
    
      System.out.println("For Payment: " +p++ );
      System.out.println( String.format("Principal paid is: $ %.2f",  + principal));
    
      balance=balance-principal;
      System.out.println( String.format("Remaining balance is: $ %.2f",
        + balance));
    
    
     }
    
    
    
    
    
    
    
    
      System.exit(0);
    
    
      }

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    continue outside of loop;
    Where is the loop statement? There are several:
    for(...) { }
    while(cond) { }
    do{} while()

    find symbol method ConfirmOption(<nulltype>,java.lang.String,int);
    What does the API doc for the JOptionPane say? Does it have a ConfirmOption() method?

  12. #12
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Read into loops here: The while and do-while Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

    A do while loop may work great for you if the line of code must run at least once and has no specific amount of times it can be run.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  13. #13
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default

    oh.. I give up. I cant find anything on making loops with a joption... I just cant seem to get my head around how an if statement works with joption to ask a user to continue the program or return to the main, and setting a loop up for this to happen seems impossible... Thanks for the help any ways

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    Can you write a description in English of the steps you want your program to do. Write short statements.
    For example
    Java Code:
    begin loop
      get input from user
      test if valid input
      if not valid input, continue at the top of the loop
      do something with the input
      if there is no more stuff to do - break out of the loop
    end loop  - here we will loop back to the start of the loop
    When you get a design, then write the loop.
    When you get a loop, write code to get the input.
    When you get the input, write a test for it.
    etc

  15. #15
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    I'm curious, if you're only just starting Java. How are you learning it that is making you use GUI right off the bat?

    But Norm is correct, you should always have some pseudocode or a flow chart before you start programming that way you know how you want your program to work.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  16. #16
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default

    Well, its an assignment, but the requirements were to make a program that calculates a mortgage, then run a loop to show amortization, then/and prompt the user to either enter another loan amount or continue with the amortization or exit the program. I got the first two parts working flawlessly, with some big help from norm. But i cant seem to figure out how to ask the user to start from the top of the program (enter another amount) or continue the program (show the amortization of the current imputed loan). So this is where i get lost, should the loop start within or right before the amortization loop? If i write a continue statement asking the user to continue, will it not only be for that loop its in, not the loop that shows the amortization? how would i combine two loops? I dont even know where to start, i mean i have the concept of what needs to happen, but i dont know enough about java to fully get the extent of how the syntax works. Im waaay better with SQL, that is kiddy stuff compared to this though. I was thinking that there is just a confirm dialog that can either keep going with the program or just return to main to start over... But i was totally wrong with that.

  17. #17
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Are you using console input for the amount or are you building a gui?
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  18. #18
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default

    Im using a GUI, here is the full code. /**/ is where i am trying to build this part im stuck at.

    Java Code:
    
    import javax.swing.*;
    
    
    
    public class MortgageApp3 {
    	public static void main(String args[])
    		{
    
    
    		double loan,
    		 interest_yr,
    		 years,
    		 interest_mo,
    		 loan_pmts,
    		 payments,
    		 new_balance,
    		 interest,
    		 interestamt,
    		 principal,
    		 principalamt,
    		 payamt,
    		 balance;
    
    	     int p;
    
            //Above is all the varaibles used for calculations
    
    
    
    
            String loanamt,
    		  interest_peryr,
    	      yearstot,
    	      pay_amt,
    	      cont,
    	      restart;
    	    //The above declares the strings for the program
    
    
    
    
    	 loanamt= JOptionPane.showInputDialog("Enter Loan Amount");    //Obtains input from user for loan amount
    	 interest_peryr=JOptionPane.showInputDialog("Enter the Interest Percentage: Example 5.6");  //Obtains input from user for interest %
    	 yearstot=JOptionPane.showInputDialog("Enter Loan Period in Years");  //Obtains input for length of loan
    
    
    
    
         // Below is the code to parse stings into doubles
    	 loan=Double.parseDouble(loanamt);
    	 interest_yr=Double.parseDouble(interest_peryr);
    	 years=Double.parseDouble(yearstot);
    
    
    
    
         interest_mo = (interest_yr/12.0)/100.0; // Turns percent whole numbers into decimals
    
         loan_pmts= years * 12;  //Gets total amount of months the loan will last after user inputs length of loan in years
    
         payments = (loan*interest_mo/(1- Math.pow((1+interest_mo),-loan_pmts))); //Loan calculation
    
    
    	 JOptionPane.showMessageDialog (null, String.format( "Your payment is: $ %.2f ", + payments)); //Shows payment with 2 decimal places
    
    
         principalamt= payments - (loan *interest_mo);  //calculates principle
    
         JOptionPane.showMessageDialog(null, String.format( "your prinicple paid is: $ %.2f ", + principalamt)); //shows principle with 2 decimal places
    
         interestamt= payments-principalamt ;  //calculates interest
    
         JOptionPane.showMessageDialog(null, String.format( "your interest paid is: $ %.2f ", + interestamt)); //shows interest with 2 decimal places
    
    
    /*do(cont=JOptionPane.ConfirmOption(null,"Would you like to see the amoritization of current loan?",
        while JOptionPane.YES_NO_OPTION);
          (cont.equals(true)));
          {continue;};
          if(cont.equals(false));
          {return main};*/
    
    
    
    
    //below is the loop
       p=1;
      balance=loan;
      
      for(int month=0;month<(years*12);month++)
    
    
    
      {
      	interest=balance*interest_mo;
      //System.out.println("interest "+interest);
    
      principal=payments-interest;
      //System.out.println("principal "+ principal);
    
      System.out.println("For Payment: " +p++ );
      System.out.println( String.format("Principal paid is: $ %.2f",  + principal));
    
      balance=balance-principal;
      System.out.println( String.format("Remaining balance is: $ %.2f",
        + balance));
    
    
     }
    
    
    
    
    
    
    
    
      System.exit(0);
    
    
      }
    
    }

  19. #19
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default

    tweaked it some:
    Java Code:
    cont=JOptionPane.ConfirmOption(null,"Would you like to see the amoritization of current loan?",
       JOptionPane.YES_NO_OPTION);
           while (cont.equals(true)));
          {continue;};
          if (cont.equals(false));
          {return main;};
    getting illegal start of expression exception

  20. #20
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    I dont even know where to start,
    i have the concept of what needs to happen
    I suggested earlier that you write out the steps you want to do in a list of simple steps.

    Don't try to solve ALL of the problems at the same time. Isolate each of them to a simple problem and solve that problem. In some cases write a small program to work on that problem alone. When you solve it you can merge the logic into the big program.
    Dark, Fubarable and DarrylBurke like this.

Page 1 of 2 12 LastLast

Similar Threads

  1. Multi-Panel multi-class GUI communication
    By manji51 in forum AWT / Swing
    Replies: 4
    Last Post: 05-25-2011, 01:54 PM
  2. Replies: 5
    Last Post: 10-01-2010, 09:26 PM
  3. JAX-WS\METRO - apt with option option key="r"
    By Talkinjive in forum Web Frameworks
    Replies: 0
    Last Post: 01-31-2010, 04:15 PM
  4. Why doesn't this work? (multi-type array)
    By 711groove in forum New To Java
    Replies: 2
    Last Post: 12-18-2009, 09:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •