I have the following program to write:
Write a program that performs the following: 1. Declare an array of size 20 of type XYPoint. 2. Fill the array with 20 random points. The x- and y-coordinates should contain values between -1000 and 1000 3. Print the contents of the array to the screen. 4. Calculate the radius of the smallest circle, centered at the origin, that will enclose all of the points. This must be done after ALL of the points have been create. 5. Print the radius.
This is my program so far:
import net.apcs.classes.XYPoint;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class EncloseInCircle {
public static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
XYPoint a[];
a = new XYPoint[20];
XYPoint random;
for (int i = 0; i < a.length; i++) {
Random rand = new Random();
int x = (rand.nextInt(1001) + 10000);
int y = (rand.nextInt(1001) + 10000);
random = new XYPoint(x, y);
a[i] = random;
}
System.out.println(Arrays.toString(a));
}
}
I'm not quite sure how to find the radius of a circle that encloses all the random points in my array... Any help would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire