148k views
5 votes
Write a method that takes a RegularPolygon as a parameter, sets its number of sides to a random integer between 10 and 20 inclusive, and sets its side length to a random decimal number greater than or equal to 5 and less than 12. Use Math.random() to generate random numbers.

This method must be called randomize() and it must take an RegularPolygon parameter.


Could someone help me out here thanks! C:

User Ambit
by
3.7k points

1 Answer

1 vote

Answer:

public static void randomize(RegularPolygon r){

int side = (int)((20-10) * Math.random()) + 10;

int length = (int)((12-5) * Math.random()) + 5;

// assuming the regularpolygon class has setSide and setLength methods.

r.set.Side(side);

r.setLength(length);

}

Step-by-step explanation:

The randomize method is used to access and change the state of the RegularPolygon class attributes sides and length. The method accepts the class as an argument and assigns a random number of sides and length to the polygon object.

User Enneppi
by
3.8k points