package PointsRun;

import example1.*;

public class PointsRun {

	public static void main(String[] args) {
		Point[] pointsArray = new Point[10];
		
		
		fillArray(pointsArray);
		printData(pointsArray);
		
		System.out.println();
		
		maxSearch(pointsArray);
		
		Point greaterDistanceFromOrig = maxSearch(pointsArray);
		System.out.println("The farhtest point is: " + greaterDistanceFromOrig + " the distance is " + Point.getDistanceFromOrig(greaterDistanceFromOrig));
	}



	private static Point maxSearch(Point[] pointsArray) {
		double maxDistance = 0.0;
		Point greaterPoint = new Point();
		
		for(Point p : pointsArray) {
			double distance = Point.getDistanceFromOrig(p);
			if (distance > maxDistance) {
				maxDistance = distance;
				greaterPoint = p;
			}
		}
		
		return greaterPoint;
	}



	private static void fillArray(Point[] pointsArray) {
		for(int i=0;i<pointsArray.length;i++) {
			pointsArray[i] = new Point(Math.random(), Math.random()); 
		}
	}

	
	private static void printData(Point[] pointsArray) {
		for(Point p : pointsArray) {
			System.out.println(p);
		}
	}
	

}