• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help needed with loop for random generated bar graph applet

 
Brynn Kishbaugh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all! Hope everyone is doing well.

Me and a group mate are working on a project for our java class which is requiring us to create an applet that will do the following..

Randomly generate 5 bars for a graph
Value for each bar needs to be a random number generated between 5 and 30

We are having trouble coming up with the coding for the generator, our loop is producing bars but they are so incorrect.
The way the graph should look


if anyone could give us an idea of how the loop should be for this, we would really appreciate it (ps: we have a deadline of 8pm tonight EST)

THANKS SO MUCH!!!

[ April 24, 2006: Message edited by: Brynn Kishbaugh ]
[ April 24, 2006: Message edited by: Brynn Kishbaugh ]
 
Joe Ess
Bartender
Posts: 9337
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what does your loop look like now?
 
samir Sadiki
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry I don't understand exactly what your problem is.But, if it' s only how to generate 5 random numbers between 5 and 30 then you cloud use:
import java.util.Random
//


//
Random r = new Random();
int H1 = r.nextInt(26) + 5;
int H2 = r.nextInt(26) + 5;
int H3 = r.nextInt(26) + 5;
int H4 = r.nextInt(26) + 5;
int H5 = r.nextInt(26) + 5;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic