[Subject: Java Programming] Create a Java Program called Point that does the fol
ID: 3762889 • Letter: #
Question
[Subject: Java Programming] Create a Java Program called Point that does the following. -the point class has two instance variables x and y. Both instance variables will have type double. Both instance variables will be private. -create two constructors: a default no argument constructor and a constructor that takes two integers as arguments(representing x and y coordinates). -create accessors(getters) and mutators(setters) methods for each instance variable. -implement the following instance methods: public double distFromOrg() public double DistFromPoint(Point P) public int whatQuadrant() public double slope(Point P)Finally in the main method(in the Point class) do the following: -create 3 point objects values of x and y coordinates can be defined by YOU. -print the three point objects to the console showing their x and y coordinates. -compute the distance between two point objects. Which two point objects is up to you. Print the distance to the console. -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. -compute the slope of a line passing through two point objects. Which two point objects is up to you. Print the slope to the console. -determine which quadrant all three point objects are in. Print the quadrants to the console.
Example Output: Point 1 x-coord: 3.00 y-coord: 2.00 Point 2 x-coord: 2.00 y-coord: -5.00 Point 3 x-coord: -1.00 y-coord: 2.00 Distance between Point 1 and Point 2: 7.0710678118654755 Distance between Point 3 and the origin(0,0): 2.23606797749979 Slope of a line passing through Point 1 and Point 2: 7.0 Point 1 is in quadrant 1 Point 2 is in quadrant 4 Point 3 is in quadrant 2 [Subject: Java Programming] Create a Java Program called Point that does the following. -the point class has two instance variables x and y. Both instance variables will have type double. Both instance variables will be private. -create two constructors: a default no argument constructor and a constructor that takes two integers as arguments(representing x and y coordinates). -create accessors(getters) and mutators(setters) methods for each instance variable. -implement the following instance methods: public double distFromOrg() public double DistFromPoint(Point P) public int whatQuadrant() public double slope(Point P)
Finally in the main method(in the Point class) do the following: -create 3 point objects values of x and y coordinates can be defined by YOU. -print the three point objects to the console showing their x and y coordinates. -compute the distance between two point objects. Which two point objects is up to you. Print the distance to the console. -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. -compute the slope of a line passing through two point objects. Which two point objects is up to you. Print the slope to the console. -determine which quadrant all three point objects are in. Print the quadrants to the console.
Example Output: Point 1 x-coord: 3.00 y-coord: 2.00 Point 2 x-coord: 2.00 y-coord: -5.00 Point 3 x-coord: -1.00 y-coord: 2.00 Distance between Point 1 and Point 2: 7.0710678118654755 Distance between Point 3 and the origin(0,0): 2.23606797749979 Slope of a line passing through Point 1 and Point 2: 7.0 Point 1 is in quadrant 1 Point 2 is in quadrant 4 Point 3 is in quadrant 2 -the point class has two instance variables x and y. Both instance variables will have type double. Both instance variables will be private. -create two constructors: a default no argument constructor and a constructor that takes two integers as arguments(representing x and y coordinates). -create accessors(getters) and mutators(setters) methods for each instance variable. -implement the following instance methods: public double distFromOrg() public double DistFromPoint(Point P) public int whatQuadrant() public double slope(Point P)
Finally in the main method(in the Point class) do the following: -create 3 point objects values of x and y coordinates can be defined by YOU. -print the three point objects to the console showing their x and y coordinates. -compute the distance between two point objects. Which two point objects is up to you. Print the distance to the console. -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. -compute the slope of a line passing through two point objects. Which two point objects is up to you. Print the slope to the console. -determine which quadrant all three point objects are in. Print the quadrants to the console.
Example Output: Point 1 x-coord: 3.00 y-coord: 2.00 Point 2 x-coord: 2.00 y-coord: -5.00 Point 3 x-coord: -1.00 y-coord: 2.00 Distance between Point 1 and Point 2: 7.0710678118654755 Distance between Point 3 and the origin(0,0): 2.23606797749979 Slope of a line passing through Point 1 and Point 2: 7.0 Point 1 is in quadrant 1 Point 2 is in quadrant 4 Point 3 is in quadrant 2
Explanation / Answer
public class Point {
private double x, y;
public Point() {
this.x = 0;
this.y = 0;
}
public Point(double x, double y) {
this.x = x;
this.y = y;
}
/**
* @return the x
*/
public double getX() {
return x;
}
/**
* @return the y
*/
public double getY() {
return y;
}
/**
* @param x
* the x to set
*/
public void setX(double x) {
this.x = x;
}
/**
* @param y
* the y to set
*/
public void setY(double y) {
this.y = y;
}
public double distFromOrg() {
return Math.sqrt(x * x + y * y);
}
public double DistFromPoint(Point P) {
return Math.sqrt((P.x - x) * (P.x - x) + (P.y - y) * (P.y - y));
}
public int whatQuadrant() {
if (x > 0 && y > 0)
return 1;
else if (x < 0 && y > 0)
return 2;
else if (x < 0 && y < 0)
return 3;
else
return 4;
}
public double slope(Point P) {
return (P.y - y) / (P.x - x);
}
public String toString() {
return "x-coord: " + x + " y-coord: " + y;
}
public static void main(String args[]) {
Point p1 = new Point(3.00, 2.00);
Point p2 = new Point(2.00, -5.00);
Point p3 = new Point(-1.00, 2.00);
System.out.println("Point 1 " + p1);
System.out.println("Point 2 " + p2);
System.out.println("Point 3 " + p3);
System.out.println("Distance between Point 1 and Point 2 :"
+ p1.DistFromPoint(p2));
System.out.println("Distance between Point 3 and the origin(0,0):"
+ p3.distFromOrg());
System.out
.println("Slope of a line passing through Point 1 and Point 2:"
+ p1.slope(p2));
System.out.println("Point 1 is in quadrant " + p1.whatQuadrant());
System.out.println("Point 2 is in quadrant " + p2.whatQuadrant());
System.out.println("Point 3 is in quadrant " + p3.whatQuadrant());
}
}
OUTPUT:
Point 1 x-coord: 3.0 y-coord: 2.0
Point 2 x-coord: 2.0 y-coord: -5.0
Point 3 x-coord: -1.0 y-coord: 2.0
Distance between Point 1 and Point 2 :7.0710678118654755
Distance between Point 3 and the origin(0,0):2.23606797749979
Slope of a line passing through Point 1 and Point 2:7.0
Point 1 is in quadrant 1
Point 2 is in quadrant 4
Point 3 is in quadrant 2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.