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

PDF
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
PPTX
OBJECT ORIENTED PROGRAMMIING LANGUAGE PROGRAMS
PPTX
lab programs on java and dbms for students access
PDF
Interfacepackage PJ1; public interface SimpleFractionInterface.pdf
PDF
operating system linux,ubuntu,Mac Geometri.pdf
DOCX
C# labprograms
PDF
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
DOCX
Pratik Bakane C++
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
OBJECT ORIENTED PROGRAMMIING LANGUAGE PROGRAMS
lab programs on java and dbms for students access
Interfacepackage PJ1; public interface SimpleFractionInterface.pdf
operating system linux,ubuntu,Mac Geometri.pdf
C# labprograms
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Pratik Bakane C++

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

PDF
Class 6 2ciclo
PDF
java write a program to evaluate the postfix expressionthe program.pdf
PDF
mainpublic class AssignmentThree {    public static void ma.pdf
PDF
Please read the comment ins codeExpressionTree.java-------------.pdf
DOCX
Algoritmos sujei
PDF
Integration Project Inspection 3
PDF
Please help!!I wanted to know how to add a high score to this prog.pdf
PDF
@author public class Person{   String sname, .pdf
PDF
Unittests für Dummies
PDF
StackInterface An interface for the ADT stack. Do not modif.pdf
DOCX
C# programs
PDF
I wanted to change the cloudsrectangles into an actuall image it do.pdf
PDF
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
PDF
Confitura 2012 Bad Tests, Good Tests
PPT
2012 JDays Bad Tests Good Tests
PDF
GeeCON 2012 Bad Tests, Good Tests
DOCX
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
PDF
Java Programpublic class Fraction {   instance variablesin.pdf
PDF
hi i have to write a java program involving link lists. i have a pro.pdf
Class 6 2ciclo
java write a program to evaluate the postfix expressionthe program.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
Algoritmos sujei
Integration Project Inspection 3
Please help!!I wanted to know how to add a high score to this prog.pdf
@author public class Person{   String sname, .pdf
Unittests für Dummies
StackInterface An interface for the ADT stack. Do not modif.pdf
C# programs
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
Confitura 2012 Bad Tests, Good Tests
2012 JDays Bad Tests Good Tests
GeeCON 2012 Bad Tests, Good Tests
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
Java Programpublic class Fraction {   instance variablesin.pdf
hi i have to write a java program involving link lists. i have a pro.pdf

More from anandshingavi23 (20)

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

Recently uploaded (20)

PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Lesson notes of climatology university.
PPTX
Pharma ospi slides which help in ospi learning
PDF
Classroom Observation Tools for Teachers
PPTX
Cell Types and Its function , kingdom of life
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Computing-Curriculum for Schools in Ghana
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Microbial diseases, their pathogenesis and prophylaxis
Abdominal Access Techniques with Prof. Dr. R K Mishra
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
TR - Agricultural Crops Production NC III.pdf
RMMM.pdf make it easy to upload and study
Insiders guide to clinical Medicine.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Lesson notes of climatology university.
Pharma ospi slides which help in ospi learning
Classroom Observation Tools for Teachers
Cell Types and Its function , kingdom of life
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Supply Chain Operations Speaking Notes -ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

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