Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    14
    Rep Power
    0
    Originally Posted by NormR
    Use an if statement to test the size of the order and skip doing it if too small
    Did that but obviously did it wrong or else I wouldn't have this issue. Gonna try to rework what I did for my previous "if" statement and see what I can make work. "If" statements right now are my biggest issue of what we've learned so far.

    Code:
     // determine if subtotal is greater than 50
         if ( subtotal < 50 )
         {
        subtotalJTextField.setText( "subtotal greater than 50" );
  2. #17
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    The if test and the message don't agree. The < operator is less than.
    > is greater than
  4. #18
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    14
    Rep Power
    0
    Originally Posted by NormR
    The if test and the message don't agree. The < operator is less than.
    > is greater than
    I originally had > listed but changed it. I've currently changed it back but its still trying to show a discount for amounts under 50.
  6. #19
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    Can you post the section of code that you are working on and explain what the code does and what you want the code to do?
  8. #20
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    14
    Rep Power
    0
    Originally Posted by NormR
    Can you post the section of code that you are working on and explain what the code does and what you want the code to do?
    Code:
    // determine if subtotal is greater than 50
    			if ( subtotal > 50 )
    			{
    			subtotalJTextField.setText( "subtotal greater than 50" );
    			}
    			
    	       // display information message
    			JOptionPane.showMessageDialog( null,
    			"7% discount will be applied.",
    			"Discount Offer", JOptionPane.INFORMATION_MESSAGE );
    First I had to create an if statement to determine if the order was greater than 50. That would be the first set of code you see here.
    Second I had to create a dialog box to let the user know if their order was over 50 they are entitled to a 7% discount. I successfully created the dialog box in the second section of code. However, the dialog box appears even on orders under 50. Until I fix my issues here, I can't proceed to the next part of the task at hand.
  10. #21
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    the dialog box appears even on orders under 50.
    What keeps the code from executing the dialog box?
    There is an if statement that controls when this message: "subtotal greater than 50" is displayed in a text field.

    You can use an if statement the same way to control when the dialog box appears.
  12. #22
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    14
    Rep Power
    0
    Originally Posted by NormR
    What keeps the code from executing the dialog box?
    There is an if statement that controls when this message: "subtotal greater than 50" is displayed in a text field.

    You can use an if statement the same way to control when the dialog box appears.
    Actually with some tweaking I've gotten everything to function as needed. The only thing that I can't seem to make work is subtracting the discount from the subtotal. I need to be able to make the program calculate by adding the subtotal to tax and minus any discount. Then display the new total. However when I use something like...

    Code:
    // calculate and display total
    double total = subtotal - discount;
    totalJTextField.setText( dollars.format( total ) );
    It doesn't do anything. I don't get any compile errors but its not calculating either.
  14. #23
  15. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    but its not calculating either.
    Please explain what happens. How do you know it is not calculating?
    To see what the values of the variables are that are used in the calculations, use a println statement to print out their values:
    System.out.println("an ID "+ <The name of the variable here>);
  16. #24
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    14
    Rep Power
    0
    Originally Posted by NormR
    Please explain what happens. How do you know it is not calculating?
    To see what the values of the variables are that are used in the calculations, use a println statement to print out their values:
    System.out.println("an ID "+ <The name of the variable here>);
    Instead of subtracting the discount from the subtotal and displaying the total, it is ignoring the discount. Basically it does subtotal + tax = total completely skipping the negative number displayed in the discount box. It should be subtracting that number before displaying the total.
  18. #25
  19. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    Please add the println statements to print out the values of all the variables used in the calculations, execute the program and copy the output and paste it here to show exactly what you are talking about.
  20. #26
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    14
    Rep Power
    0
    Originally Posted by NormR
    Please add the println statements to print out the values of all the variables used in the calculations, execute the program and copy the output and paste it here to show exactly what you are talking about.
    I have found the cause of my problem. Its because its not displaying the subtotal in the subtotalJTextField. The calculation can't compute with a blank JTextField.
  22. #27
  23. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    Something like this after the statement where the variable is used and where its values are changed:

    System.out.println("variable's name here "+ <The name of the variable here>);
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo