Page 2 of 2 FirstFirst 12
Results 21 to 32 of 32
Like Tree3Likes

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

  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    getting illegal start of expression exception
    When you get an error message, post the full text of the message. This message you posted does not say where the error occurred.

    Can you write a short list of simple steps describing what you want to do in those 6 lines of code you posted?
    Include the decisions that must be made at each step.

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

    Default

    Thats what i was trying to do, instead of making a 3 option jpane, i was going to try to just get one to work, then make 3 of them one after another to ask a series of questions...

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

    Default

    Java Code:
    cont=JOptionPane.ConfirmOption(null,"Would you like to see the amoritization of current loan?", //Ask to see the amoritization
       JOptionPane.YES_NO_OPTION);  // gives the box a yes or no
           while (cont.equals(true))); //this is where i assume the loops starts to see if button pressed is true or not
          {continue;};   continue threw the loop to start the amortization loop
          if (cont.equals(false)); //if not return to main
          {return main;};  //return to main
    and the exception was on the line where while starts

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

    Default

    Java Code:
    while (cont.equals(true))[color=red][b]);[/b][/color]
    This line of code is wrong, see the bold section for the error.

    You are ending the while statement before you allow yourself to enter into the loop. You are also doing the same thing here.

    Java Code:
    if (cont.equals(false))[color=red][b];[/b][/color] //if not return to main
    • 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.

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

    Default

    Java Code:
    cont=JOptionPane.ConfirmOption(null,"Would you like to see the amoritization of current loan?", //exception:cannot find symbol method ConfirmOption(<nulltype>,java.lang.String,int)
       JOptionPane.YES_NO_OPTION);
           while (cont.equals(true))
          {continue;};
          if (cont.equals(false))
          {return main;};  //Exception:cannot return a value from method whose result type is void

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

    Default

    Now the syntax is correct, you need to place your code properly into the loops and if statements.

    I suggest something like this:
    Java Code:
    do
    {
        //Your code that must be run multiple times.
        //Get input from user here
        if (userInput.equals("Whatever I want to check")
        {
           //If its true, then do this code
        }
        else
        {
          //If its not true, then do this
        }
    }
    while(Condition to repeat must be true)
    • 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.

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

    Default

    I dont know, cus i already have a for loop repeating what i need to be repeated.
    Java Code:
    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));
    
    
     }

    But Where the heck would i start this loop for the whole program to start over? I mean i dont understand why i needa loop, isnt there a way to just return to the main string?? My syntax on the above loop isnt working either, the return aprt isnt working and either is the joptiopn, Is there any other way of doing this besides joption?

  8. #28
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Where the heck would i start this loop for the whole program to start over
    Its possible to have loops within loops.
    You could have one loop that spans the whole of the method. To start that method over at the head of the loop, use the continue statement.

    Is there any other way of doing this besides joption?
    For testing, forget about asking the user for a number. Just hardcode a value for the answer for testing.
    Make a comment to remind yourself to come back later and fix it.
    Don't let every problem stop progress on the whole program. Isolate/hard code some of the problems and come back to them later.

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

    Default

    Essentially wrapping the entire code that needs to be repeated, not just your calculation one, in a while loop will make the whole program repeat itself after it finishes once through the code. You would have to then make the input decide where it goes. Honestly I can't really explain to you how you would do it in your code, you just need to learn about loops. Its obvious your understanding of loops is very minimal and I'm not sure how I'm supposed to explain it to you any further. Read the link I posted on while and do while loops.

    You could use recursion, but I think a loop would be easier for you. You could split your program up into separate classes and have your main just call each one in order depending on the user input. Either way, it would be easier for you with what you have already written to just adjust it to work in a loop.
    • 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.

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

    Default

    Ok, im a little closer, i got the joption working, but now how do i get the loop to read the inputs from the user? where do i put the while statement?

    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,cont;
    
    	     int p;
    
            //Above is all the varaibles used for calculations
    
    
    
            String loanamt,
    		  interest_peryr,
    	      yearstot,
    	      pay_amt,
    	      restart;
    	    //The above declares the strings for the program
    
    
    
            
              cont = JOptionPane.showConfirmDialog(null, "Want to enter a loan?", "Loan Calcuator",
                                          JOptionPane.YES_NO_OPTION);
              while(cont.equals(YES_OPTION)){continue;};
              if (cont.equals(NO_OPTION)){system.exit(0);   /////////////////////////////////THIS IS WHERE I AM STUCK
    }
    }
    
    
    
    
    	 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
    
    
    
    
    
    
    //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);
    
    
      }
    
    }

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

    Default

    or is the while supposed to be at the very end of the code? like this?

    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,cont;
    
    	     int p;
    
            //Above is all the varaibles used for calculations
    
    
    
            String loanamt,
    		  interest_peryr,
    	      yearstot,
    	      pay_amt,
    	      restart;
    	    //The above declares the strings for the program
    
    
    
            do{
    
    
    
    
    
    	 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
    
    
    
    
    
    
    //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));
    
    
     }
            }
    
    
       while(cont.equals(YES_OPTION));{continue;};
              if (cont.equals(NO_OPTION)){system.exit(0);
    }
    }
    
    
    
    
      }

  12. #32
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    You need to fix the formatting of your code. What you posted is not readable.
    You've been told on another thread how to fix this. Please fix your formatting.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Multi-Panel multi-class GUI communication
    By manji51 in forum AWT / Swing
    Replies: 4
    Last Post: 05-25-2011, 02:54 PM
  2. Replies: 5
    Last Post: 10-01-2010, 10: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, 05: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, 10: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
  •