programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# Drawing a Histogram ( I know its been covered and I have read through those posts)

Greenhorn
Posts: 11
• Number of slices to send:
Optional 'thank-you' note:
I edited this and hopefully this will work .
Basically I am trying to draw a histogram from the results of a dice roll. Two dice actually.
I have already written the code to determine the probabilities and now need to write a drawHor() method.

My teachers instructions were to :
1) limit size of histogram to maxLength
2) scale the data in the values array when we copy it into the instance copy of the data in the array.
Do # 2 using 2 loops. First loop find the largest values in the array "values".
Second loop multiplies each value in the values array by the max length we want for bars ( which is maxLength) and divides
by maxValue.

3)The drawHor() method needs to be in two nested loops. Outer will scan through each element of the array and the inner loop will
put an * from 1 through the value in the out loop element of the values array.
Print the values array integer at the end of each bar of asterisks.

That is my code so far. I stuck. I do not expect an answer or even code in the response. I just need to know what I should be looking at learning more about and where I am going wrong. Maybe a link or something. I have been on java tutorial for hours and reading my book. ( Along with "head first java"). Thank you so much for your time it is truly appreciated.

p.s. Sorry Rob Camick, I run dual monitors and one is wide screen. Hope this fixes it.

Rancher
Posts: 3324
32
• Number of slices to send:
Optional 'thank-you' note:
I am having trouble reading your question because I have to continually scroll the window horizontally to read the entire line of text. Maybe you use a resolution greater than 1024 and don't see the problem?

The reason for the horozontal scrolling is because your comment lines are so large. So why don't make it easier for us to read your question by splitting the comments onto multiple lines. Of course there is not guarantee I will understand the question, but as it stands right now I'm not even going to bother to read the question.

Ranch Hand
Posts: 44
• Number of slices to send:
Optional 'thank-you' note:
I'm thinking it would be a good idea for you to try to do some pseudo-code programming. As far as I can see, you're not that far away from the goal.
You have already described the flow of the program, or at least your teacher has.

Perhaps I should get you started with some high level pseudo-code:

Iterate over your values[] array and find the index of the largest value (maxValueIndex).
Use values[maxValueIndex] to figure out what value to multiply by, resulting in the values[maxValueIndex] = maxLength.
Multiply all your array values by that value.
Now your array contains values which are directly usable by the drawHor() method.
Now do that double looping described by your teacher in 3)

Kind regards,
Janus

dante cass
Greenhorn
Posts: 11
• Number of slices to send:
Optional 'thank-you' note:
Is this the correct way to find the max value?

Iterate over your values[] array and find the index of the largest value (maxValueIndex).

Rob Camick
Rancher
Posts: 3324
32
• Number of slices to send:
Optional 'thank-you' note:
> Is this the correct way to find the max value?

Does it give you the correct answer?

dante cass
Greenhorn
Posts: 11
• Number of slices to send:
Optional 'thank-you' note:
I believe it did. I am making progress btw. I have been able to print out the values of the rolls between 2 and 12.
I came up with this code

The result is this....
Value2: 20
Value3: 51
Value4: 73
Value5: 120
Value6: 141
Value7: 158
Value8: 137
Value9: 139
Value10: 77
Value11: 57
Value12: 27

Which is what I needed. Now I just need to figure out how to draw a scaled histogram of * before the value result. I know I have to use a nested for loop. but dont really know how...

Janus EngstrÃ¸m
Ranch Hand
Posts: 44
• Number of slices to send:
Optional 'thank-you' note:
Well, you already have the first loop ... you only need to insert another loop in the body of the first.
This loop inside another loop is also known as a nested loop, so try to see if you can get some info using that keyword in a google search... at least I found some decent info.

Kind regards,
Janus

dante cass
Greenhorn
Posts: 11
• Number of slices to send:
Optional 'thank-you' note:
I solved it. I have to run to class. But just in case anyone was following, or for future googlers and people who helped. I will explain and post later. Thanks for your input guys, I have been reading through the site a bunch and can tell it will help greatly.

 Consider Paul's rocket mass heater.