SlideShare a Scribd company logo
1 of 18
Download to read offline
public class Point {
/* Insert your name here */
private double x;
private double y;
public static final double EPSILON = 1e-5;
public static boolean debug = false;
// TODO Implement Point.Point(double x, double y)
/**
* instantiate a point "this.x" refers to the instance variable of the
* object x refers to the parameter same for this.y and y
*/
public Point(double x, double y) {
// System.out.println("Point(x,y) not implemented yet");
this.x = x;
this.y = y;
}
// TODO Implement Point.Point()
/**
* Point() creates the origin by appropriately calling the general Point
* constructor
*/
public Point() {
// System.out.println("Point() not implemented yet");
this.x = 0;
this.y = 0;
}
// TODO Implement Point.getX
/**
* return x
*/
public double getX() {
// System.out.println("getX not implemented yet");
return this.x;
}
// TODO Implement Point.getY
/**
* return y
*/
public double getY() {
// System.out.println("getY not implemented yet");
return this.y;
}
// Given Point.toString
/**
* convert to String
*/
public String toString() {
return "(" + x + "," + y + ")";
}
// TODO Implement Point.equals
/**
*
* param p other point return test for equality using epsilon, because we
* are dealing with doubles,so roundoff can occur
*/
public boolean equals(Point p) {
// System.out.println("equals not implemented yet");
if (p.getX() == this.getX() && p.getY() == this.getY())
return true;
else
return false;
}
// Given equals(Object o)
/**
* We need this equals method for ArrayList, because the generic
* ArrayList is really an ArrayList of Object. In the case of equals, the
* signature is public boolean equals(Object o) and the method below
* overrides the Object equals method and the calls the class's
* equals(Point) method
*
* see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (obj instanceof Point) {
Point p = (Point) obj;
return equals(p);
}
return false;
}
// TODO Implement Point.euclidDist
/**
*
* param p return Euclidean distance of this point to point p
*/
public double euclidDist(Point p) {
// System.out.println("euclidDist not implemented yet");
double X = this.getY() - p.getY();
double Y = this.getX() - p.getX();
double result = Math.sqrt(X * X + Y * Y);
return result;
}
/**
* param args: no args
*/
public static void main(String[] args) {
// test all methods
if (debug)
System.out.println("debug ON");
else
System.out.println("debug OFF");
System.out.println("EPSILON: " + Point.EPSILON);
Point origin = new Point();
Point p1 = new Point(0.0, 4.0);
Point p2 = new Point(3.0000001, 3.9999999);
Point p3 = new Point(3.0, 4.0);
Point p4 = new Point(0.0, 5.0);
Point p5 = new Point(12.0, 0.0);
System.out.println("origin: " + origin);
System.out.println("p1: " + p1);
System.out.println("p2: " + p2);
System.out.println("p3: " + p3);
System.out.println("p4: " + p4);
System.out.println("p5: " + p5);
if (p2.equals(p3))
System.out.println(p2 + " equals " + p3);
else
System.out.println(p2 + " does not equal " + p3);
System.out.println("Euclidean distance between " + origin + " and "
+ p1 + ": " + origin.euclidDist(p1));
System.out.println("Euclidean distance between " + p1 + " and " + p3
+ ": " + p1.euclidDist(p3));
System.out.println("Euclidean distance between " + p3 + " and "
+ origin + ": " + p3.euclidDist(origin));
System.out.println("Euclidean distance between " + p4 + " and " + p5
+ ": " + p4.euclidDist(p5));
}
}
OUTPUT:
debug OFF
EPSILON: 1.0E-5
origin: (0.0,0.0)
p1: (0.0,4.0)
p2: (3.0000001,3.9999999)
p3: (3.0,4.0)
p4: (0.0,5.0)
p5: (12.0,0.0)
(3.0000001,3.9999999) does not equal (3.0,4.0)
Euclidean distance between (0.0,0.0) and (0.0,4.0): 4.0
Euclidean distance between (0.0,4.0) and (3.0,4.0): 3.0
Euclidean distance between (3.0,4.0) and (0.0,0.0): 5.0
Euclidean distance between (0.0,5.0) and (12.0,0.0): 13.0
import java.util.ArrayList;
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");
if (this.points.size() == 0)
return true;
else
return false;
}
// TODO Implement Cloud.size
/**
* return number of points in the cloud
*/
public int size() {
// System.out.println("size not implemented yet");
return this.points.size();
}
// 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");
for (int i = 0; i < points.size(); i++) {
Point point = points.get(i);
if (p.equals(point))
return true;
}
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");
points.add(p);
}
// 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");
Point center = new Point();
double sumX = 0, sumY = 0;
for (int i = 0; i < points.size(); i++) {
Point point = points.get(i);
sumX += point.getX();
sumY += point.getY();
}
return new Point(sumX / points.size(), sumY / points.size());
}
// 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);
}
}
OUTPUT:
cloud.debug OFF
cloud: []
extremes not implemented yet
minDist not implemented yet
cloud 1: [(3.0,1.0), (2.0,2.0), (4.0,2.0), (3.0,3.0)]
centerP not implemented yet
center point in cloud: (3.0,2.0)
cloud: [(3.0,1.0), (2.0,2.0), (4.0,2.0), (3.0,3.0)]
cloud 2: [(3.0,1.0), (2.0,2.0), (4.0,2.0), (3.0,3.0)]
OK: point (7.0,7.0) is not in cloud
extremes not implemented yet
minDist not implemented yet
min dist in cloud: 0.000
Test cloud with 1 point
minDist not implemented yet
min dist in cloud1: 0.000
NOTE:
Not enough time to complete the the question
Solution
public class Point {
/* Insert your name here */
private double x;
private double y;
public static final double EPSILON = 1e-5;
public static boolean debug = false;
// TODO Implement Point.Point(double x, double y)
/**
* instantiate a point "this.x" refers to the instance variable of the
* object x refers to the parameter same for this.y and y
*/
public Point(double x, double y) {
// System.out.println("Point(x,y) not implemented yet");
this.x = x;
this.y = y;
}
// TODO Implement Point.Point()
/**
* Point() creates the origin by appropriately calling the general Point
* constructor
*/
public Point() {
// System.out.println("Point() not implemented yet");
this.x = 0;
this.y = 0;
}
// TODO Implement Point.getX
/**
* return x
*/
public double getX() {
// System.out.println("getX not implemented yet");
return this.x;
}
// TODO Implement Point.getY
/**
* return y
*/
public double getY() {
// System.out.println("getY not implemented yet");
return this.y;
}
// Given Point.toString
/**
* convert to String
*/
public String toString() {
return "(" + x + "," + y + ")";
}
// TODO Implement Point.equals
/**
*
* param p other point return test for equality using epsilon, because we
* are dealing with doubles,so roundoff can occur
*/
public boolean equals(Point p) {
// System.out.println("equals not implemented yet");
if (p.getX() == this.getX() && p.getY() == this.getY())
return true;
else
return false;
}
// Given equals(Object o)
/**
* We need this equals method for ArrayList, because the generic
* ArrayList is really an ArrayList of Object. In the case of equals, the
* signature is public boolean equals(Object o) and the method below
* overrides the Object equals method and the calls the class's
* equals(Point) method
*
* see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (obj instanceof Point) {
Point p = (Point) obj;
return equals(p);
}
return false;
}
// TODO Implement Point.euclidDist
/**
*
* param p return Euclidean distance of this point to point p
*/
public double euclidDist(Point p) {
// System.out.println("euclidDist not implemented yet");
double X = this.getY() - p.getY();
double Y = this.getX() - p.getX();
double result = Math.sqrt(X * X + Y * Y);
return result;
}
/**
* param args: no args
*/
public static void main(String[] args) {
// test all methods
if (debug)
System.out.println("debug ON");
else
System.out.println("debug OFF");
System.out.println("EPSILON: " + Point.EPSILON);
Point origin = new Point();
Point p1 = new Point(0.0, 4.0);
Point p2 = new Point(3.0000001, 3.9999999);
Point p3 = new Point(3.0, 4.0);
Point p4 = new Point(0.0, 5.0);
Point p5 = new Point(12.0, 0.0);
System.out.println("origin: " + origin);
System.out.println("p1: " + p1);
System.out.println("p2: " + p2);
System.out.println("p3: " + p3);
System.out.println("p4: " + p4);
System.out.println("p5: " + p5);
if (p2.equals(p3))
System.out.println(p2 + " equals " + p3);
else
System.out.println(p2 + " does not equal " + p3);
System.out.println("Euclidean distance between " + origin + " and "
+ p1 + ": " + origin.euclidDist(p1));
System.out.println("Euclidean distance between " + p1 + " and " + p3
+ ": " + p1.euclidDist(p3));
System.out.println("Euclidean distance between " + p3 + " and "
+ origin + ": " + p3.euclidDist(origin));
System.out.println("Euclidean distance between " + p4 + " and " + p5
+ ": " + p4.euclidDist(p5));
}
}
OUTPUT:
debug OFF
EPSILON: 1.0E-5
origin: (0.0,0.0)
p1: (0.0,4.0)
p2: (3.0000001,3.9999999)
p3: (3.0,4.0)
p4: (0.0,5.0)
p5: (12.0,0.0)
(3.0000001,3.9999999) does not equal (3.0,4.0)
Euclidean distance between (0.0,0.0) and (0.0,4.0): 4.0
Euclidean distance between (0.0,4.0) and (3.0,4.0): 3.0
Euclidean distance between (3.0,4.0) and (0.0,0.0): 5.0
Euclidean distance between (0.0,5.0) and (12.0,0.0): 13.0
import java.util.ArrayList;
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");
if (this.points.size() == 0)
return true;
else
return false;
}
// TODO Implement Cloud.size
/**
* return number of points in the cloud
*/
public int size() {
// System.out.println("size not implemented yet");
return this.points.size();
}
// 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");
for (int i = 0; i < points.size(); i++) {
Point point = points.get(i);
if (p.equals(point))
return true;
}
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");
points.add(p);
}
// 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");
Point center = new Point();
double sumX = 0, sumY = 0;
for (int i = 0; i < points.size(); i++) {
Point point = points.get(i);
sumX += point.getX();
sumY += point.getY();
}
return new Point(sumX / points.size(), sumY / points.size());
}
// 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);
}
}
OUTPUT:
cloud.debug OFF
cloud: []
extremes not implemented yet
minDist not implemented yet
cloud 1: [(3.0,1.0), (2.0,2.0), (4.0,2.0), (3.0,3.0)]
centerP not implemented yet
center point in cloud: (3.0,2.0)
cloud: [(3.0,1.0), (2.0,2.0), (4.0,2.0), (3.0,3.0)]
cloud 2: [(3.0,1.0), (2.0,2.0), (4.0,2.0), (3.0,3.0)]
OK: point (7.0,7.0) is not in cloud
extremes not implemented yet
minDist not implemented yet
min dist in cloud: 0.000
Test cloud with 1 point
minDist not implemented yet
min dist in cloud1: 0.000
NOTE:
Not enough time to complete the the question

More Related Content

Similar to public class Point {   Insert your name here    private dou.pdf

java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfarjuntelecom26
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdffathimafancyjeweller
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfshanki7
 
Algoritmos sujei
Algoritmos sujeiAlgoritmos sujei
Algoritmos sujeigersonjack
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3Dillon Lee
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfJUSTSTYLISH3B2MOHALI
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdfaplolomedicalstoremr
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfARCHANASTOREKOTA
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdffeelinggifts
 
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdfListings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdfRAJATCHUGH12
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsTomek Kaczanowski
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good TestsTomek Kaczanowski
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsTomek Kaczanowski
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxssuser454af01
 
Java Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfJava Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfaroramobiles1
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfarchgeetsenterprises
 
There is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdfThere is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdfaashienterprisesuk
 

Similar to public class Point {   Insert your name here    private dou.pdf (20)

java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
 
Algoritmos sujei
Algoritmos sujeiAlgoritmos sujei
Algoritmos sujei
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
C# programs
C# programsC# programs
C# programs
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdf
 
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdfListings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good Tests
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
 
Java Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfJava Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdf
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
Php 5.6
Php 5.6Php 5.6
Php 5.6
 
There is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdfThere is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdf
 

More from anandshingavi23

You need to provide the data for the 4 other meas.pdf
                     You need to provide the data for the 4 other meas.pdf                     You need to provide the data for the 4 other meas.pdf
You need to provide the data for the 4 other meas.pdfanandshingavi23
 
When an acid reacts with a base produces a salt &.pdf
                     When an acid reacts with a base produces a salt &.pdf                     When an acid reacts with a base produces a salt &.pdf
When an acid reacts with a base produces a salt &.pdfanandshingavi23
 
The one with the lowest Ksp will precipitate firs.pdf
                     The one with the lowest Ksp will precipitate firs.pdf                     The one with the lowest Ksp will precipitate firs.pdf
The one with the lowest Ksp will precipitate firs.pdfanandshingavi23
 
Riboflavin (Vitamin B2) consists of the sugar alc.pdf
                     Riboflavin (Vitamin B2) consists of the sugar alc.pdf                     Riboflavin (Vitamin B2) consists of the sugar alc.pdf
Riboflavin (Vitamin B2) consists of the sugar alc.pdfanandshingavi23
 
molar mass, or atomic weight, its true False. .pdf
                     molar mass, or atomic weight, its true    False. .pdf                     molar mass, or atomic weight, its true    False. .pdf
molar mass, or atomic weight, its true False. .pdfanandshingavi23
 
just multiply 806 by the molar mass of water and .pdf
                     just multiply 806 by the molar mass of water and .pdf                     just multiply 806 by the molar mass of water and .pdf
just multiply 806 by the molar mass of water and .pdfanandshingavi23
 
Image is not visible, kindly repost. .pdf
                     Image is not visible, kindly repost.             .pdf                     Image is not visible, kindly repost.             .pdf
Image is not visible, kindly repost. .pdfanandshingavi23
 
When it comes categorizing hazardous waste, the EPA has broken it do.pdf
When it comes categorizing hazardous waste, the EPA has broken it do.pdfWhen it comes categorizing hazardous waste, the EPA has broken it do.pdf
When it comes categorizing hazardous waste, the EPA has broken it do.pdfanandshingavi23
 
Visual hacking is used to visually capture private,sensitive informa.pdf
Visual hacking is used to visually capture private,sensitive informa.pdfVisual hacking is used to visually capture private,sensitive informa.pdf
Visual hacking is used to visually capture private,sensitive informa.pdfanandshingavi23
 
The standards used for the various layers in an Ethernet-based netwo.pdf
The standards used for the various layers in an Ethernet-based netwo.pdfThe standards used for the various layers in an Ethernet-based netwo.pdf
The standards used for the various layers in an Ethernet-based netwo.pdfanandshingavi23
 
The probability of at least one goal is P(X 1) = 1SolutionTh.pdf
The probability of at least one goal is P(X  1) = 1SolutionTh.pdfThe probability of at least one goal is P(X  1) = 1SolutionTh.pdf
The probability of at least one goal is P(X 1) = 1SolutionTh.pdfanandshingavi23
 
The end result of double fertilization is zygote and edosperm. In th.pdf
The end result of double fertilization is zygote and edosperm. In th.pdfThe end result of double fertilization is zygote and edosperm. In th.pdf
The end result of double fertilization is zygote and edosperm. In th.pdfanandshingavi23
 
The conus medullaris (Latin for medullary cone) is the tapered, .pdf
The conus medullaris (Latin for medullary cone) is the tapered, .pdfThe conus medullaris (Latin for medullary cone) is the tapered, .pdf
The conus medullaris (Latin for medullary cone) is the tapered, .pdfanandshingavi23
 
D is the answer take care .pdf
                     D is the answer  take care                       .pdf                     D is the answer  take care                       .pdf
D is the answer take care .pdfanandshingavi23
 
Endothermic or exothermic reaction nature .pdf
                     Endothermic or exothermic reaction nature        .pdf                     Endothermic or exothermic reaction nature        .pdf
Endothermic or exothermic reaction nature .pdfanandshingavi23
 
Step1 mass of 1 litre of sea water = 1.025x1000 =1025 g Step2 ma.pdf
Step1 mass of 1 litre of sea water = 1.025x1000 =1025 g Step2 ma.pdfStep1 mass of 1 litre of sea water = 1.025x1000 =1025 g Step2 ma.pdf
Step1 mass of 1 litre of sea water = 1.025x1000 =1025 g Step2 ma.pdfanandshingavi23
 
Solution66. Candida albicans is vaginal Yeast infection or “Thrus.pdf
Solution66. Candida albicans is vaginal Yeast infection or “Thrus.pdfSolution66. Candida albicans is vaginal Yeast infection or “Thrus.pdf
Solution66. Candida albicans is vaginal Yeast infection or “Thrus.pdfanandshingavi23
 
Rate of formation of P2O5=rate of reaction Rate of formation =2.9.pdf
Rate of formation of P2O5=rate of reaction Rate of formation =2.9.pdfRate of formation of P2O5=rate of reaction Rate of formation =2.9.pdf
Rate of formation of P2O5=rate of reaction Rate of formation =2.9.pdfanandshingavi23
 
Solution Lymphoid stem cell is a type of blood stem cells.These s.pdf
Solution Lymphoid stem cell is a type of blood stem cells.These s.pdfSolution Lymphoid stem cell is a type of blood stem cells.These s.pdf
Solution Lymphoid stem cell is a type of blood stem cells.These s.pdfanandshingavi23
 
copper sulphate when added to 5 moles of water ge.pdf
                     copper sulphate when added to 5 moles of water ge.pdf                     copper sulphate when added to 5 moles of water ge.pdf
copper sulphate when added to 5 moles of water ge.pdfanandshingavi23
 

More from anandshingavi23 (20)

You need to provide the data for the 4 other meas.pdf
                     You need to provide the data for the 4 other meas.pdf                     You need to provide the data for the 4 other meas.pdf
You need to provide the data for the 4 other meas.pdf
 
When an acid reacts with a base produces a salt &.pdf
                     When an acid reacts with a base produces a salt &.pdf                     When an acid reacts with a base produces a salt &.pdf
When an acid reacts with a base produces a salt &.pdf
 
The one with the lowest Ksp will precipitate firs.pdf
                     The one with the lowest Ksp will precipitate firs.pdf                     The one with the lowest Ksp will precipitate firs.pdf
The one with the lowest Ksp will precipitate firs.pdf
 
Riboflavin (Vitamin B2) consists of the sugar alc.pdf
                     Riboflavin (Vitamin B2) consists of the sugar alc.pdf                     Riboflavin (Vitamin B2) consists of the sugar alc.pdf
Riboflavin (Vitamin B2) consists of the sugar alc.pdf
 
molar mass, or atomic weight, its true False. .pdf
                     molar mass, or atomic weight, its true    False. .pdf                     molar mass, or atomic weight, its true    False. .pdf
molar mass, or atomic weight, its true False. .pdf
 
just multiply 806 by the molar mass of water and .pdf
                     just multiply 806 by the molar mass of water and .pdf                     just multiply 806 by the molar mass of water and .pdf
just multiply 806 by the molar mass of water and .pdf
 
Image is not visible, kindly repost. .pdf
                     Image is not visible, kindly repost.             .pdf                     Image is not visible, kindly repost.             .pdf
Image is not visible, kindly repost. .pdf
 
When it comes categorizing hazardous waste, the EPA has broken it do.pdf
When it comes categorizing hazardous waste, the EPA has broken it do.pdfWhen it comes categorizing hazardous waste, the EPA has broken it do.pdf
When it comes categorizing hazardous waste, the EPA has broken it do.pdf
 
Visual hacking is used to visually capture private,sensitive informa.pdf
Visual hacking is used to visually capture private,sensitive informa.pdfVisual hacking is used to visually capture private,sensitive informa.pdf
Visual hacking is used to visually capture private,sensitive informa.pdf
 
The standards used for the various layers in an Ethernet-based netwo.pdf
The standards used for the various layers in an Ethernet-based netwo.pdfThe standards used for the various layers in an Ethernet-based netwo.pdf
The standards used for the various layers in an Ethernet-based netwo.pdf
 
The probability of at least one goal is P(X 1) = 1SolutionTh.pdf
The probability of at least one goal is P(X  1) = 1SolutionTh.pdfThe probability of at least one goal is P(X  1) = 1SolutionTh.pdf
The probability of at least one goal is P(X 1) = 1SolutionTh.pdf
 
The end result of double fertilization is zygote and edosperm. In th.pdf
The end result of double fertilization is zygote and edosperm. In th.pdfThe end result of double fertilization is zygote and edosperm. In th.pdf
The end result of double fertilization is zygote and edosperm. In th.pdf
 
The conus medullaris (Latin for medullary cone) is the tapered, .pdf
The conus medullaris (Latin for medullary cone) is the tapered, .pdfThe conus medullaris (Latin for medullary cone) is the tapered, .pdf
The conus medullaris (Latin for medullary cone) is the tapered, .pdf
 
D is the answer take care .pdf
                     D is the answer  take care                       .pdf                     D is the answer  take care                       .pdf
D is the answer take care .pdf
 
Endothermic or exothermic reaction nature .pdf
                     Endothermic or exothermic reaction nature        .pdf                     Endothermic or exothermic reaction nature        .pdf
Endothermic or exothermic reaction nature .pdf
 
Step1 mass of 1 litre of sea water = 1.025x1000 =1025 g Step2 ma.pdf
Step1 mass of 1 litre of sea water = 1.025x1000 =1025 g Step2 ma.pdfStep1 mass of 1 litre of sea water = 1.025x1000 =1025 g Step2 ma.pdf
Step1 mass of 1 litre of sea water = 1.025x1000 =1025 g Step2 ma.pdf
 
Solution66. Candida albicans is vaginal Yeast infection or “Thrus.pdf
Solution66. Candida albicans is vaginal Yeast infection or “Thrus.pdfSolution66. Candida albicans is vaginal Yeast infection or “Thrus.pdf
Solution66. Candida albicans is vaginal Yeast infection or “Thrus.pdf
 
Rate of formation of P2O5=rate of reaction Rate of formation =2.9.pdf
Rate of formation of P2O5=rate of reaction Rate of formation =2.9.pdfRate of formation of P2O5=rate of reaction Rate of formation =2.9.pdf
Rate of formation of P2O5=rate of reaction Rate of formation =2.9.pdf
 
Solution Lymphoid stem cell is a type of blood stem cells.These s.pdf
Solution Lymphoid stem cell is a type of blood stem cells.These s.pdfSolution Lymphoid stem cell is a type of blood stem cells.These s.pdf
Solution Lymphoid stem cell is a type of blood stem cells.These s.pdf
 
copper sulphate when added to 5 moles of water ge.pdf
                     copper sulphate when added to 5 moles of water ge.pdf                     copper sulphate when added to 5 moles of water ge.pdf
copper sulphate when added to 5 moles of water ge.pdf
 

Recently uploaded

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Recently uploaded (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

public class Point {   Insert your name here    private dou.pdf

  • 1. public class Point { /* Insert your name here */ private double x; private double y; public static final double EPSILON = 1e-5; public static boolean debug = false; // TODO Implement Point.Point(double x, double y) /** * instantiate a point "this.x" refers to the instance variable of the * object x refers to the parameter same for this.y and y */ public Point(double x, double y) { // System.out.println("Point(x,y) not implemented yet"); this.x = x; this.y = y; } // TODO Implement Point.Point() /** * Point() creates the origin by appropriately calling the general Point * constructor */ public Point() { // System.out.println("Point() not implemented yet"); this.x = 0; this.y = 0; } // TODO Implement Point.getX /** * return x */ public double getX() { // System.out.println("getX not implemented yet"); return this.x; } // TODO Implement Point.getY
  • 2. /** * return y */ public double getY() { // System.out.println("getY not implemented yet"); return this.y; } // Given Point.toString /** * convert to String */ public String toString() { return "(" + x + "," + y + ")"; } // TODO Implement Point.equals /** * * param p other point return test for equality using epsilon, because we * are dealing with doubles,so roundoff can occur */ public boolean equals(Point p) { // System.out.println("equals not implemented yet"); if (p.getX() == this.getX() && p.getY() == this.getY()) return true; else return false; } // Given equals(Object o) /** * We need this equals method for ArrayList, because the generic * ArrayList is really an ArrayList of Object. In the case of equals, the * signature is public boolean equals(Object o) and the method below * overrides the Object equals method and the calls the class's * equals(Point) method * * see java.lang.Object#equals(java.lang.Object)
  • 3. */ public boolean equals(Object obj) { if (obj instanceof Point) { Point p = (Point) obj; return equals(p); } return false; } // TODO Implement Point.euclidDist /** * * param p return Euclidean distance of this point to point p */ public double euclidDist(Point p) { // System.out.println("euclidDist not implemented yet"); double X = this.getY() - p.getY(); double Y = this.getX() - p.getX(); double result = Math.sqrt(X * X + Y * Y); return result; } /** * param args: no args */ public static void main(String[] args) { // test all methods if (debug) System.out.println("debug ON"); else System.out.println("debug OFF"); System.out.println("EPSILON: " + Point.EPSILON); Point origin = new Point(); Point p1 = new Point(0.0, 4.0); Point p2 = new Point(3.0000001, 3.9999999); Point p3 = new Point(3.0, 4.0); Point p4 = new Point(0.0, 5.0); Point p5 = new Point(12.0, 0.0);
  • 4. System.out.println("origin: " + origin); System.out.println("p1: " + p1); System.out.println("p2: " + p2); System.out.println("p3: " + p3); System.out.println("p4: " + p4); System.out.println("p5: " + p5); if (p2.equals(p3)) System.out.println(p2 + " equals " + p3); else System.out.println(p2 + " does not equal " + p3); System.out.println("Euclidean distance between " + origin + " and " + p1 + ": " + origin.euclidDist(p1)); System.out.println("Euclidean distance between " + p1 + " and " + p3 + ": " + p1.euclidDist(p3)); System.out.println("Euclidean distance between " + p3 + " and " + origin + ": " + p3.euclidDist(origin)); System.out.println("Euclidean distance between " + p4 + " and " + p5 + ": " + p4.euclidDist(p5)); } } OUTPUT: debug OFF EPSILON: 1.0E-5 origin: (0.0,0.0) p1: (0.0,4.0) p2: (3.0000001,3.9999999) p3: (3.0,4.0) p4: (0.0,5.0) p5: (12.0,0.0) (3.0000001,3.9999999) does not equal (3.0,4.0) Euclidean distance between (0.0,0.0) and (0.0,4.0): 4.0 Euclidean distance between (0.0,4.0) and (3.0,4.0): 3.0 Euclidean distance between (3.0,4.0) and (0.0,0.0): 5.0 Euclidean distance between (0.0,5.0) and (12.0,0.0): 13.0 import java.util.ArrayList; public class Cloud {
  • 5. 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"); if (this.points.size() == 0) return true; else return false; } // TODO Implement Cloud.size /** * return number of points in the cloud */ public int size() { // System.out.println("size not implemented yet"); return this.points.size(); } // TODO Implement Cloud.hasPoint /** * * param p a Point return whether p in the cloud */ public boolean hasPoint(Point p) {
  • 6. // System.out.println("hasPoint not implemented yet"); for (int i = 0; i < points.size(); i++) { Point point = points.get(i); if (p.equals(point)) return true; } 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"); points.add(p); } // 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
  • 7. * null; */ public Point centerP() { System.out.println("centerP not implemented yet"); Point center = new Point(); double sumX = 0, sumY = 0; for (int i = 0; i < points.size(); i++) { Point point = points.get(i); sumX += point.getX(); sumY += point.getY(); } return new Point(sumX / points.size(), sumY / points.size()); } // 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"); } /**
  • 8. * 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]);
  • 9. 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); } } OUTPUT: cloud.debug OFF cloud: [] extremes not implemented yet minDist not implemented yet cloud 1: [(3.0,1.0), (2.0,2.0), (4.0,2.0), (3.0,3.0)] centerP not implemented yet center point in cloud: (3.0,2.0) cloud: [(3.0,1.0), (2.0,2.0), (4.0,2.0), (3.0,3.0)] cloud 2: [(3.0,1.0), (2.0,2.0), (4.0,2.0), (3.0,3.0)] OK: point (7.0,7.0) is not in cloud extremes not implemented yet minDist not implemented yet min dist in cloud: 0.000 Test cloud with 1 point minDist not implemented yet min dist in cloud1: 0.000 NOTE: Not enough time to complete the the question Solution public class Point { /* Insert your name here */
  • 10. private double x; private double y; public static final double EPSILON = 1e-5; public static boolean debug = false; // TODO Implement Point.Point(double x, double y) /** * instantiate a point "this.x" refers to the instance variable of the * object x refers to the parameter same for this.y and y */ public Point(double x, double y) { // System.out.println("Point(x,y) not implemented yet"); this.x = x; this.y = y; } // TODO Implement Point.Point() /** * Point() creates the origin by appropriately calling the general Point * constructor */ public Point() { // System.out.println("Point() not implemented yet"); this.x = 0; this.y = 0; } // TODO Implement Point.getX /** * return x */ public double getX() { // System.out.println("getX not implemented yet"); return this.x; } // TODO Implement Point.getY /** * return y */
  • 11. public double getY() { // System.out.println("getY not implemented yet"); return this.y; } // Given Point.toString /** * convert to String */ public String toString() { return "(" + x + "," + y + ")"; } // TODO Implement Point.equals /** * * param p other point return test for equality using epsilon, because we * are dealing with doubles,so roundoff can occur */ public boolean equals(Point p) { // System.out.println("equals not implemented yet"); if (p.getX() == this.getX() && p.getY() == this.getY()) return true; else return false; } // Given equals(Object o) /** * We need this equals method for ArrayList, because the generic * ArrayList is really an ArrayList of Object. In the case of equals, the * signature is public boolean equals(Object o) and the method below * overrides the Object equals method and the calls the class's * equals(Point) method * * see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { if (obj instanceof Point) {
  • 12. Point p = (Point) obj; return equals(p); } return false; } // TODO Implement Point.euclidDist /** * * param p return Euclidean distance of this point to point p */ public double euclidDist(Point p) { // System.out.println("euclidDist not implemented yet"); double X = this.getY() - p.getY(); double Y = this.getX() - p.getX(); double result = Math.sqrt(X * X + Y * Y); return result; } /** * param args: no args */ public static void main(String[] args) { // test all methods if (debug) System.out.println("debug ON"); else System.out.println("debug OFF"); System.out.println("EPSILON: " + Point.EPSILON); Point origin = new Point(); Point p1 = new Point(0.0, 4.0); Point p2 = new Point(3.0000001, 3.9999999); Point p3 = new Point(3.0, 4.0); Point p4 = new Point(0.0, 5.0); Point p5 = new Point(12.0, 0.0); System.out.println("origin: " + origin); System.out.println("p1: " + p1); System.out.println("p2: " + p2);
  • 13. System.out.println("p3: " + p3); System.out.println("p4: " + p4); System.out.println("p5: " + p5); if (p2.equals(p3)) System.out.println(p2 + " equals " + p3); else System.out.println(p2 + " does not equal " + p3); System.out.println("Euclidean distance between " + origin + " and " + p1 + ": " + origin.euclidDist(p1)); System.out.println("Euclidean distance between " + p1 + " and " + p3 + ": " + p1.euclidDist(p3)); System.out.println("Euclidean distance between " + p3 + " and " + origin + ": " + p3.euclidDist(origin)); System.out.println("Euclidean distance between " + p4 + " and " + p5 + ": " + p4.euclidDist(p5)); } } OUTPUT: debug OFF EPSILON: 1.0E-5 origin: (0.0,0.0) p1: (0.0,4.0) p2: (3.0000001,3.9999999) p3: (3.0,4.0) p4: (0.0,5.0) p5: (12.0,0.0) (3.0000001,3.9999999) does not equal (3.0,4.0) Euclidean distance between (0.0,0.0) and (0.0,4.0): 4.0 Euclidean distance between (0.0,4.0) and (3.0,4.0): 3.0 Euclidean distance between (3.0,4.0) and (0.0,0.0): 5.0 Euclidean distance between (0.0,5.0) and (12.0,0.0): 13.0 import java.util.ArrayList; public class Cloud { private ArrayList points; private boolean debug = false; /**
  • 14. * 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"); if (this.points.size() == 0) return true; else return false; } // TODO Implement Cloud.size /** * return number of points in the cloud */ public int size() { // System.out.println("size not implemented yet"); return this.points.size(); } // 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"); for (int i = 0; i < points.size(); i++) { Point point = points.get(i);
  • 15. if (p.equals(point)) return true; } 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"); points.add(p); } // 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() {
  • 16. System.out.println("centerP not implemented yet"); Point center = new Point(); double sumX = 0, sumY = 0; for (int i = 0; i < points.size(); i++) { Point point = points.get(i); sumX += point.getX(); sumY += point.getY(); } return new Point(sumX / points.size(), sumY / points.size()); } // 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) {
  • 17. 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();
  • 18. 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); } } OUTPUT: cloud.debug OFF cloud: [] extremes not implemented yet minDist not implemented yet cloud 1: [(3.0,1.0), (2.0,2.0), (4.0,2.0), (3.0,3.0)] centerP not implemented yet center point in cloud: (3.0,2.0) cloud: [(3.0,1.0), (2.0,2.0), (4.0,2.0), (3.0,3.0)] cloud 2: [(3.0,1.0), (2.0,2.0), (4.0,2.0), (3.0,3.0)] OK: point (7.0,7.0) is not in cloud extremes not implemented yet minDist not implemented yet min dist in cloud: 0.000 Test cloud with 1 point minDist not implemented yet min dist in cloud1: 0.000 NOTE: Not enough time to complete the the question