how do i generate 4 random numbers ?
Printable View
how do i generate 4 random numbers ?
In this assignment you will write a program to generate random boxes on a 500 x 500 pixel screen. You are to have the program draw 30 boxes. The boxes must have a random position and a random height and width. Make sure that all boxes show up in the window. Here are a couple more stipulations:
1. If the boxes have a width less than 15 they need to be filled in with magenta.
2. If the boxes have a height less than 50 and a width greater than 15 they need to be filled in with blue.
3. All other boxes are just drawn and not filled in.
import javax.swing.*;
import java.awt.*;
public class as19 extends JFrame {
Container con = getContentPane();
public as19(){
con.setBackground(Color.BLUE);
}
public void paint(Graphics gr){
super.paint(gr);
gr.setColor(Color.RED);
for(int i = 1;i <= 30;i++){
for(int j = 1;j <= i;j++){
System.out.print(i);
}
System.out.println();
}
}
//generate 4 random numbers
//if statements for what to draw
}
public static void main(String [] args){
as19 frame = new as19();
frame.setSize(200,200);
frame.setVisible(true);
}
}
heres what i got so far
Here's a quick video tutorial that will tell you how to do everything from scratch...
Java Programming Tutorial - 26 - Random Number Generator - YouTube
In this assignment you will write a program to generate random boxes on a 500 x 500 pixel screen. You are to have the program draw 30 boxes. The boxes must have a random position and a random height and width. Make sure that all boxes show up in the window. Here are a couple more stipulations:
1. If the boxes have a width less than 15 they need to be filled in with magenta.
2. If the boxes have a height less than 50 and a width greater than 15 they need to be filled in with blue.
3. All other boxes are just drawn and not filled in
heres what i got so far
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class as19 extends JFrame {
Container con = getContentPane();
public as19(){
con.setBackground(Color.BLUE);
}
public void paint(Graphics gr){
super.paint(gr);
gr.setColor(Color.RED);
for(int i = 1;i <= 30;i++){
for(int j = 1;j <= i;j++){
System.out.print(i);
}
System.out.println();
}
}
Random random = new Random();
int value = random(10000);
//if statements for what to draw
public static void main(String [] args){
as19 frame = new as19();
frame.setSize(200,200);
frame.setVisible(true);
}
private int random(int i) {
// TODO Auto-generated method stub
return 0;
}
}
Don't double post. I've merged the two threads.
Also, don't post homework questions in Advanced Java.
db