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 -
Need help with a class that can be called to do math
Page 2 - Discuss Need help with a class that can be called to do math in the Java Help forum on Dev Shed. Need help with a class that can be called to do math 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:
|
|
|

January 30th, 2013, 03:04 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
What is the use of the toString variable? Why is it in the program?
What do you expect this statement to do:
Code:
toString = toString;
The variable on the left side is the same one that is on the right side of the =.
What that will do is take the value of toString and put it back into toString.
That doesn't change anything.
|

January 30th, 2013, 03:15 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 12
Time spent in forums: 2 h 39 m 38 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by NormR What is the use of the toString variable? Why is it in the program?
What do you expect this statement to do:
Code:
toString = toString;
The variable on the left side is the same one that is on the right side of the =.
What that will do is take the value of toString and put it back into toString.
That doesn't change anything. |
If Im understanding correctly its supposed to relay the value of price*unitsOnHand to the message in the main method.
My teacher didn't really cover it in very much detail.
|

January 30th, 2013, 03:25 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
Quote: | its supposed to relay the value of price*unitsOnHand to the message |
What is the "its"? There are two different things we are talking about : the variable: toStriing and the method: toString(). Which one is the "its" you are refering to? It's important to use proper terms and descriptions when talking about programs to avoid confusion.
You've said that you know the difference between a method and a variable.
Did you see this?
What do you expect this statement to do:
Code:
toString = toString;
The variable on the left side is the same one that is on the right side of the =.
What that will do is take the value of toString and put it back into toString.
That code doesn't change anything.
|

January 30th, 2013, 03:30 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 12
Time spent in forums: 2 h 39 m 38 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by jworkman5985 If Im understanding correctly its supposed to relay the value of price*unitsOnHand to the message in the main method.
My teacher didn't really cover it in very much detail. |
I think I'm understanding now. I am talking about the method. So the reason its not returning a value is that I am missing the parenthesis?
Code:
message = String.format( "Jacket \t $", jacket.toString ());
|

January 30th, 2013, 03:39 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
Ok, that's good; get rid of the toString variable and use the method; with the ()s
Now what value is the toString() method returning? To see what values it has to work with, add a call to the println method in the toString() method before the return statement that prints out the values of the two variables that are used to compute the value that is returned. Seeing their values could help you see what the code is doing.
Code:
System.out.println(<PUT THE VARIABLES HERE WITH +" " + BETWEEN THEM);
Last edited by NormR : January 30th, 2013 at 03:43 PM.
|

January 30th, 2013, 03:45 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 12
Time spent in forums: 2 h 39 m 38 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by NormR Ok, that's good; get rid of the toString variable and use the method; with the ()s
Now what value is the toString() method returning? To see what values it has to work with, add a call to the println method in the toString() method before the return statement that prints out the values of the two variables that are used to compute the value that is returned. Seeing their values could help you see what the code is doing.
Code:
System.out.println(<PUT THE VARIABLES HERE WITH +" " + BETWEEN THEM);
|
Thanks for the advice and all of your help. I won't be able to compile until I get home (Im at work until 8p) but I will try this and let you know.
Sorry for being such a noob and thank you for your patience!
|

January 30th, 2013, 03:47 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
See you later then.
|
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
|
|
|
|
|