Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help debugging code  RSS feed

 
Lloyd Wilson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering if any one would help in debuging m .java program. I do not want to post it on the board. If you want to help email me at adgtrunklid@attbi.com Thank you...
 
Rikko Verrijzer
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Have you already tried assertions, System.out/System.err (or other logging methods) or just a debugger? Also a description of what kind of trouble you are having might help you find people willing to help. Last but not least, why don't you want to post your program? That might improve your chances in getting help.
Rikko
 
Lloyd Wilson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK here is the code. The problem is it keeps generating the same price for day 2 day 3 etc.. It should generate a new amount for each day.

 
Joe Pluta
Ranch Hand
Posts: 1376
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a quick comment - I hope you'll take the time to factor out the common code in this example. You should be able to create a method called "nextDay" that will do the same instructions for each day that you want to report. But that's a different topic for a different time.
To address your question, from what I can read, the method str.generatecrprice() is what you expect to change the current price of the stock. We won't be able to help unless you let us see that code.
Also, just as a little hint, I've found it to be a common Java practice to use the following technique to name a method:
First, don't abbreviate words unless really necessary. You have lots of room to work with, and the more information in the name the better. Second, the normal convention is to capitalize every word in the method name, except the first. Using these conventions, I would probably have named the method "generateCurrentPrice". The same sorts of rules apply for variables and class names as well, except that with class names the first word is also capitalized.
Just a couple of things I've learned over time.
Joe
 
Lloyd Wilson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the other code, oh yesno looping
 
Rikko Verrijzer
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Could it be that you forgot to proper init the prprice variable? leaving it at 0, means that the following line will always return a 0. (0 times something is 0)

if this is the case crprice will stay at 0.0
Hope this helps?
Rikko
 
Lloyd Wilson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rikko,
I do not quite anderstand what you mean, what should I change in the math.random line? Or better yet what should I change it too from
 
Joe Pluta
Ranch Hand
Posts: 1376
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, here's an exercise in desk-checking your code (desk-checking is the time honored tradition of actually reading through your code and visualizing what it does).
In the 17th line of your main method, you print the worth for Day 1. On the 25th line you print the worth for Day 2. In between those two lines, do you see a line of code that changes the worth?
Joe
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Trunklid ADG", I have asked you in your previous thread, to read Java Ranch's Naming Policy and change your displayed name. Please comply with my request.
Thanks,
-Barry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!