Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old February 22nd, 2013, 08:37 PM
Rahlevi Rahlevi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 14 Rahlevi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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" );

Reply With Quote
  #17  
Old February 22nd, 2013, 08:58 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 3,040 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 36 m 54 sec
Reputation Power: 346
The if test and the message don't agree. The < operator is less than.
> is greater than

Reply With Quote
  #18  
Old February 22nd, 2013, 11:03 PM
Rahlevi Rahlevi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 14 Rahlevi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #19  
Old February 23rd, 2013, 06:26 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 3,040 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 36 m 54 sec
Reputation Power: 346
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?

Reply With Quote
  #20  
Old February 23rd, 2013, 12:29 PM
Rahlevi Rahlevi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 14 Rahlevi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #21  
Old February 23rd, 2013, 12:33 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 3,040 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 36 m 54 sec
Reputation Power: 346
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.

Reply With Quote
  #22  
Old February 23rd, 2013, 02:27 PM
Rahlevi Rahlevi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 14 Rahlevi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #23  
Old February 23rd, 2013, 02:31 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 3,040 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 36 m 54 sec
Reputation Power: 346
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>);

Reply With Quote
  #24  
Old February 23rd, 2013, 02:35 PM
Rahlevi Rahlevi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 14 Rahlevi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #25  
Old February 23rd, 2013, 02:39 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 3,040 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 36 m 54 sec
Reputation Power: 346
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.

Reply With Quote
  #26  
Old February 23rd, 2013, 02:45 PM
Rahlevi Rahlevi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 14 Rahlevi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #27  
Old February 23rd, 2013, 02:47 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 3,040 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 36 m 54 sec
Reputation Power: 346
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>);

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Modified Fuzzy Dice

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap