SlideShare a Scribd company logo
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.pdf
arjuntelecom26
 
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
fathimafancyjeweller
 
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
shanki7
 
Algoritmos sujei
Algoritmos sujeiAlgoritmos sujei
Algoritmos sujei
gersonjack
 
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.pdf
JUSTSTYLISH3B2MOHALI
 
@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
aplolomedicalstoremr
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
Lars Jankowfsky
 
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
ARCHANASTOREKOTA
 
C# programs
C# programsC# programs
C# programs
Gourav Pant
 
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
feelinggifts
 
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
RAJATCHUGH12
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good Tests
Tomek Kaczanowski
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
Tomek 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.docx
ssuser454af01
 
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
aroramobiles1
 
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
archgeetsenterprises
 
Php 5.6
Php 5.6Php 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
aashienterprisesuk
 

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.pdf
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
Endothermic or exothermic reaction nature .pdf
                     Endothermic or exothermic reaction nature        .pdf                     Endothermic or exothermic reaction nature        .pdf
Endothermic or exothermic reaction nature .pdf
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 
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
anandshingavi23
 

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

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 

Recently uploaded (20)

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 

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