import java.util.Arrays; public class Cloud { /* insert your name here */ private Point[] points; // Array of Points contained in this Cloud private int maxSize; // The maximum number of points allowed in this Cloud private int size; // The current number of points in this Cloud /** * * pre: None * post: returns true if the Cloud is full * * A Cloud is defined as full when the current number of points * in the Cloud is equal to the maximum number of points in the * Cloud. */ public boolean isFull(){ return size == maxSize; } /** * * pre: None * post: returns true when the Cloud is empty * * A Cloud is defined as empty when there are no Points in the * Cloud. */ public boolean isEmpty(){ return size == 0; } /** * * pre: p is a Valid point * post: returns true if the Point p is contained in the Cloud * *The intuition here is to look through the points array and *discover if a point that is equal to the argument p is in that array. */ public boolean hasPoint(Point p){ boolean found = false; for(int i = 0; i 0 * post: a Cloud has been constructed, and a points * array has been created of size maxSize. */ public Cloud(int maxSize){ this.size = 0; this.maxSize = maxSize; this.points = new Point[maxSize]; } /** * * pre: p is a valid Point * post: * if (size < maxSize) add p to points, increment size * return true if p added to points, * return false if not added because size == maxSize */ public boolean addPoint(Point p){ boolean res = true; if(!isFull()){ points[size]= p; size++; } else res = false; return res; } /* * * pre: None * post: A string is returned that represents the Cloud * This string should take the form of {a,b,c} where * a, b, and c are valid representations of the points * in the Cloud * * The result of an empty Cloud would be {}. */ public String toString(){ String s = "{"; for (int i=0; i rght.getx()){ rght = points[i]; } if( y < bot.gety()){ bot = points[i]; } if( y > top.gety()){ top = points[i]; } } lrtb = new Point[4]; lrtb[0] = left; lrtb[1] = rght; lrtb[2] = top; lrtb[3] = bot; } return lrtb; } /** * * pre: None * post: return null if the Cloud is empty * otherwise, create and return the center point * * The center point is defined as the average x and the average y for all * the points in the Cloud. */ private double centerX(){ double sum = 0; for(int i=0; i 0 * @return average Y */ private double centerY(){ double sum = 0; for(int i=0; i