• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help understanding 2d array output.  RSS feed

 
Dustin Nelson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So Im slowly coming along with Java programming. Seems like its hit or miss while debugging take an hour or two try again and something might click. However I am not able to figure out this problem. I have a 2d array which receives values from Timeinp (textbox) and Earninp (textbox). I have 2 buttons. Enter, and Run Report. I also have a TextArea where the user will beable to see the information he/she has entered. The Enter button should take the Timeinp and Earninp, store it in a 2d array, and present the most recent input of both. The run report button should call the full 2d array to the TextArea. I have only been able to get the enter button to work. Such as Timeinp = 2 and Earn = 1 will display in the Text Area Time worked 2 : Earnings 1. I am unable to get the Run report button to work and I am pretty new to this so it could be something very simple. However after the enter button has been used when running the report button the Text Area is set to 0.00.0. Eithier my Enter button is not forwarding my inputs to the 2d array or I am not calling my 2d array to the textarea correctly. Any input would be greatly appreciated.

The // sections are just me brainstorming with trial and error. Sorry for the mess.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the line #29... you are creating a local variable tutorArray... is that what you want? or you have an instance variable tutorArray in which the actual save happen?

Since there is no complete runnable code, I think above might be the issue. A simple code to demonstrate the issue (note that double instance variable has a default value of 0.0 assigned to it).

 
Dustin Nelson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! out put is now correct for enter, run report however is listing in a vertical line 20 lines of only the first set of numbers I entered. I didnt think I would need to intialize all 20 array values, thought that was what the loop is for?
out put should be like this:

Report has been run!.
Time******Earnings
1********** 2
3********** 4
5********** 6

and so forth for 10 total rows. (0-9)
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch you should be able to sort your output by changing some of the println(xx) instructions to print(xxx). You may be better using printf instead.

By the way: there is no such thing as a 2D array. There is however an array of arrays, which is what you have.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!