Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Java program called Point. This project will have Point.java as its fil

ID: 3761954 • Letter: C

Question

Create a Java program called Point. This project will have Point.java as its file. The Point class will represent a point in 2-Dimensional space. – (6 points) The Point class will have two instance variables: x and y. Both instance variables will have type double. Both instance variables will be private. – (10 points) You will create two constructors: a default no argument constructor and a constructor that takes two integers as arguments(representing x and y coordinates). – (5 points) You will also create accessors(getters) and mutators(setters) methods for each instance variable. – (24 Points @ 6 points each) You will then implement the following instance methods: //Distance from Origin, Assumed to be (0,0) public double distFromOrg() //Distance between two Points public double DistFromPoint(Point P) //What Quadrant is the point object in public int whatQuadrant() //Slope between two points public double slope(Point P) Finally, in the main method(in the Point class) that does the following: – (5 points) Creates 3 Point Objects, values of x and y coordinates can be defined by YOU. – (5 points) Print the three Point objects to the console showing their x and y coordinates. – (5 points) Compute the distance between two Point objects. Which two Point objects is up to you. Print the distance to the console. – (5 points) Compute the distance between a Point object and the origin. Which Point object you used is up to you. Print the distance to the console. 1 – (5 points) Compute the slop of a line passing through two point Objects. Which two Point objects is up to you. Print the slop the console. – (5 points) Determine which quadrant all 3 Point objects are in. Print the quadrants to the console. – (10 points) Please document/comment your code where necessary.

Explanation / Answer

Point.java

/*
Chegg Expert Answer
*/

package com.student;

/**
*
* Chegg
*/
public final class Point {
private double x; // x-coordinate
private double y; // y-coordinate

// random point
public Point() {
x = Math.random();
y = Math.random();
}

// point initialized from parameters
public Point(double x, double y) {
this.x = x;
this.y = y;
}

// accessor methods
public double x()
{ return x;
}
public double y()
{ return y;
}
public double r()
{
return Math.sqrt(x*x + y*y);
}
public double theta()
{ return Math.atan2(y, x);
}

// Euclidean distance between this point and that point
public double distanceTo(Point that) {
double dx = this.x - that.x;
double dy = this.y - that.y;
return Math.sqrt(dx*dx + dy*dy);
}

// return a string representation of this point
public String toString() {
return "(" + x + ", " + y + ")";
}

// test client
public static void main(String[] args) {
Point p = new Point();
System.out.println("p = " + p);
System.out.println(" x = " + p.x());
System.out.println(" y = " + p.y());
System.out.println(" r = " + p.r());
System.out.println(" theta = " + p.theta());
System.out.println();

Point q = new Point(0.6, 0.6);
System.out.println("point q = " + q);
System.out.println("dist(p, q) = " + p.distanceTo(q));
}
}

output

p = (0.33306735302238555, 0.5662043517254984)
x = 0.33306735302238555
y = 0.5662043517254984
r = 0.6569027550271276
theta = 1.03906442664244

point q = (0.6, 0.6)
dist(p, q) = 0.26906353127982535
BUILD SUCCESSFUL (total time: 0 seconds)