I am fairly new to programming and I have to use the turtle class, drawshave method, and random class to have the turtles draw octagons in random places and sizes in the world, but my random num generator isn't working.
Error code:
----jGRASP exec: javac -g RandomTurtleFun.java
RandomTurtleFun.java:13: error: cannot find symbol
int size =gen.RandomNumberGenerator(1, 100);
^
symbol: method RandomNumberGenerator(int,int)
location: variable gen of type Random
RANDOM TURTLE FUN:
import java.util.Random;
import CSE234.World;
public class RandomTurtleFun{
//We will learn what line below does later
public static void main (String[] args) {
World earth = new World(600, 600);
Random gen = new Random();
int size =gen.RandomNumberGenerator(1, 100);
int thickness=gen.RandomNumberGenerator(1, 10);
int turn=45;
for (int i = 0; i < 3; i++) {
Turtle jose = new Turtle(size ,thickness, earth);
jose.drawShape(60,2);
}
TURTLE.JAVA CODE:
public class RandomNumberGenerator {
public static Random random = new Random();
public static int generateRandomInt(int min, int max) {
return random.nextInt((max - min) + 1) + min;
}
}
//put your drawShape method here
/* Method : drawShape
* Created by: []
* Date: 11-7-23
*/
public void drawShape(int size, int thickness) {
setPenWidth(thickness);
int turn= 45;
for (int i = 0; i < 8; i++) {
this.forward(size);
this.turn(turn);
}
}
}
Anonymous #11420022
Level 3
Issue with random number generator
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
zemiak
18 December 2023, 21:26
in your code gen is of Random class, but RandomNumberGenerator() is not in Random class, it is your 'custom' class.
use:
or because method is static:
0