The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
Page 2 -
Modified Fuzzy Dice
Page 2 - Discuss Modified Fuzzy Dice in the Java Help forum on Dev Shed. Modified Fuzzy Dice Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 22nd, 2013, 08:37 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 14
Time spent in forums: 2 h 36 m 54 sec
Reputation Power: 0
|
|
Quote: | 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" );
|

February 22nd, 2013, 08:58 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
The if test and the message don't agree. The < operator is less than.
> is greater than
|

February 22nd, 2013, 11:03 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 14
Time spent in forums: 2 h 36 m 54 sec
Reputation Power: 0
|
|
Quote: | 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.
|

February 23rd, 2013, 06:26 AM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
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?
|

February 23rd, 2013, 12:29 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 14
Time spent in forums: 2 h 36 m 54 sec
Reputation Power: 0
|
|
Quote: | 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.
|

February 23rd, 2013, 12:33 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
Quote: | 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.
|

February 23rd, 2013, 02:27 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 14
Time spent in forums: 2 h 36 m 54 sec
Reputation Power: 0
|
|
Quote: | 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.
|

February 23rd, 2013, 02:31 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
Quote: 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>);
|

February 23rd, 2013, 02:35 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 14
Time spent in forums: 2 h 36 m 54 sec
Reputation Power: 0
|
|
Quote: | 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.
|

February 23rd, 2013, 02:39 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
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.
|

February 23rd, 2013, 02:45 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 14
Time spent in forums: 2 h 36 m 54 sec
Reputation Power: 0
|
|
Quote: | 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.
|

February 23rd, 2013, 02:47 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
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>);
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|