Question: When you are happy with Point, move on to Cloud. Clouds have an ArrayList points, instance variable that will hold the points of the Cloud.

When you are happy with Point, move on to Cloud. Clouds have an ArrayList points, instance variable that will hold the points of the Cloud. The Cloud (Constructor) and toString method are provided, so we all print in the same format. Stepwise implement the following methods: isEmpty: checks if the cloud is empty. size: the number of elements in the cloud. hasPoint: uses the equals method of Point to check whether a given Point occurs in the Cloud. addPoint: if the Point is not in the cloud, adds the Point to the Cloud ***to the end*** of points, again so that we all print the same results because we keep the same order. extremes: returns null if the Cloud is empty, and an array of x and y coordinate doubles: leftmost, rightmost, top, bottom ***in that order*** otherwise. For example, if the cloud contains [ (0.0,0.0), (1.0,1.0), (2.0,0.0), (1.0,-1.0) ], the result array is [0.0, 2.0, 1.0, -1.0]. centerP: creates a center Point (average x and average y of the Cloud). minDist: returns 0.0 if the Cloud is empty or has one element, and the minimal distance between two Points, otherwise. crop: has parameters that are two Points in the Cloud. One of these two points is a bottom corner, and the other a top corner, of a rectangle. The top corner is diagonally across from the bottom corner. Crop will remove all points outside this rectangle from the Cloud much like you would crop an image. The crop method must deal with two input points on a horizontal or vertical line segment, in which case all points not on the line segment are removed, and it must deal with two equal Points p1 and p2, in which case all Points but p1 (if is exists in the cloud) are removed from the Cloud. For example, if the two input Points are (0.0,0,0) and (1.0,1.0), all Points outside the square delimited by (0.0,0.0), (0.0,1.0), (1.0,1.0), and (0.0,1.0) are removed, but if the two input Points are (0.0,0,0) and (0.0,1.0), all Points outside the line segment delimited by (0.0,0.0), and (0.0,1.0) are removed. Here is the result of running Cloud, when debug is OFF. The main method, again, does an initial test of the Cloud implementation.

import java.awt.Component; import java.util.ArrayList; import java.util.Arrays; /* Insert your name here */ public class Cloud { private ArrayList points; private boolean debug = false; /** * Given Constructor */ public Cloud(){ points = new ArrayList(); } public void setDebug(Boolean debug){ this.debug = debug; } //TODO Implement Cloud.isEmpty /** * @return whether cloud is empty or not */ public boolean isEmpty(){ System.out.println("isEmpty not implemented yet"); return false; } //TODO Implement Cloud.size /** * @return number of points in the cloud */ public int size(){ System.out.println("size not implemented yet"); return -1; } //TODO Implement Cloud.hasPoint /** * * @param p a Point * @return whether p in the cloud */ public boolean hasPoint(Point p){ System.out.println("hasPoint not implemented yet"); return false; } //TODO Implement Cloud.addPoint /** * * @param p * if p not in points, add p ***at the end*** of points (to keep same order) */ public void addPoint(Point p){ System.out.println("addPoint not implemented yet"); } //Given Cloud.toString public String toString(){ return points.toString(); } //TODO Implement Cloud.extremes /** * * @return an array of doubles: left, right, top, and bottom of points, * null for empty cloud */ public double[] extremes(){ System.out.println("extremes not implemented yet"); return null; } //TODO Implement Cloud.centerP /** * * @return: if (cloud not empty) create and return the center point * else null; */ public Point centerP(){ System.out.println("centerP not implemented yet"); return null; } //TODO Implement Cloud.minDist /** * * @return minimal distance between 2 points in the cloud * 0.0 for a cloud with less than 2 points */ public double minDist(){ System.out.println("minDist not implemented yet"); return 0.0; } //TODO Implement Cloud.crop /** * * @param p1 * @param p2 * * all Points outside the rectangle, line or point spanned * by p1 and p2 are removed * */ public void crop(Point p1, Point p2){ System.out.println("minDist not implemented yet"); } /** * @param args:no args */ public static void main(String[] args) { Cloud cloud = new Cloud(); cloud.setDebug(false); System.out.println("cloud.debug OFF"); System.out.println("cloud: " + cloud); if(!cloud.isEmpty()) System.out.println("Error: cloud should be empty!"); if(cloud.extremes()!=null) System.out.println("Error: extremes should be null!"); if(cloud.minDist()!=0.0) System.out.println("Error: minDist should return 0.0!"); Point p31 = new Point(3.0,1.0); cloud.addPoint(p31); Point p22 = new Point(2.0,2.0); cloud.addPoint(p22); Point p42 = new Point(4.0,2.0); cloud.addPoint(p42); Point p33 = new Point(3.0,3.0); cloud.addPoint(p33); System.out.println("cloud 1: " + cloud); System.out.println("center point in cloud: " + cloud.centerP()); System.out.println("cloud: " + cloud); System.out.println("cloud 2: " + cloud); Point p77 = new Point(7,7); if (cloud.hasPoint(p77)) System.out.println("Error: point " + p77 + " should not be in cloud!"); else System.out.println("OK: point " + p77 + " is not in cloud"); double[] extrs = cloud.extremes(); if(extrs!=null){ System.out.println("left: " + extrs[0]); System.out.println("right: " + extrs[1]); System.out.println("top: " + extrs[2]); System.out.println("bottom: " + extrs[3]); } double minD = cloud.minDist(); System.out.printf("min dist in cloud: %5.3f ", minD); System.out.println("Test cloud with 1 point"); Cloud cloud1 = new Cloud(); Point p = new Point(); cloud1.addPoint(p); minD = cloud1.minDist(); System.out.printf("min dist in cloud1: %5.3f ", minD); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!