Need help writing code for generating random triangles.
You will have the following functions (no violation of these interfaces) and you may have others, as needed:
− public static void GenerateRandomTriangles(int numTriangles)
to create a file RandomTriangles.dat having the following format (including some comments like the ones
shown below) with random integer coordinates (x, y) of the three vertices of a triangle. Each x and y will be a
random integer in the range 0 <= x, y < 150. (Use seed for random numbers.)
5 //numTriangles; each line below gives integer coordinates (x, y) of vertices of a triangle
( 20, 100) ( 25, 88) (112, 99)
Here is what I have so far:
public class TestTriangleType
public static void GenerateRandomTriangles(int numTriangles)
int x1,y1,x2,y2,x3,y3 = 0
Random randomInt = new Random(0);
x1 = randomInt.nextInt(150);
y1 = randomInt.nextInt(150);
do x2 = randomInt.nextInt(150);
y2 = randomInt.nextInt(150);
while (!(x1 == x2) && (y1 == y2);
do x3 = randomInt.nextInt(150);
y3 = randomInt.nextInt(150);
while (!(x2 == x3) && (y2 == y3);