Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, Please follow the instructions exactly. ONLY the main class needs to be written. The code for Class Point is already written!!! It is at

Hi,
Please follow the instructions exactly.
ONLY the main class needs to be written.
The code for Class Point is already written!!! It is at the very end of this post
It contains all the code for the methods that you call from the Main class.
The data to be read in from the text file is below the code for the Class Point.
Thanks!!!
INSTRUCTIONS
Code an application class (main class)
1.) (i.e., a class containing a main method),
2.) named PointApp that reads point data from the file points.text.
This data is then used to create pairs of Point objects which are then used to flex (i.e, illustrate) the methods of the class.
The format of the points.text file is:
x1 y1 x2 y2
i.e., pairs of x/y coordinates, resulting in data for 2 Point objects per line.
The name of your class should be PointApp.
For example, if the file points.text contains:
0 0 1 1
1 1 1 -1
1 1 -1 1
1 1 -1 -1
0 0 0 0
1 1 1 1
1 1 -2 -2
the program should produce the following output:
p1: (0, 0) (quadrant 0) / p2: (1, 1) (quadrant 1)
p1+p2: (1, 1) (quadrant 1)
The distance between (0, 0) and (1, 1) is 1.4142135623730951
p1: (1, 1) (quadrant 1) / p2: (1, -1) (quadrant 4)
p1+p2: (2, 0) (quadrant 4)
p1 and p2 are reflections across the x-axis
p1 and p2 are equidistant from the origin
The distance between (1, 1) and (1, -1) is 2.0
p1: (1, 1) (quadrant 1) / p2: (-1, 1) (quadrant 2)
p1+p2: (0, 2) (quadrant 0)
p1 and p2 are reflections across the y-axis
p1 and p2 are equidistant from the origin
The distance between (1, 1) and (-1, 1) is 2.0
p1: (1, 1) (quadrant 1) / p2: (-1, -1) (quadrant 3)
p1+p2: (0, 0) (quadrant 0)
p1 and p2 are reflections through the origin
p1 and p2 are equidistant from the origin
The distance between (1, 1) and (-1, -1) is 2.8284271247461903
p1: (0, 0) (quadrant 0) / p2: (0, 0) (quadrant 0)
p1+p2: (0, 0) (quadrant 0)
p1 and p2 are reflections across the x-axis
p1 and p2 are reflections across the y-axis
p1 and p2 are reflections through the origin
p1 and p2 are equidistant from the origin
The distance between (0, 0) and (0, 0) is 0.0
p1: (1, 1) (quadrant 1) / p2: (1, 1) (quadrant 1)
p1+p2: (2, 2) (quadrant 1)
p1 and p2 are equidistant from the origin
The distance between (1, 1) and (1, 1) is 0.0
p1: (1, 1) (quadrant 1) / p2: (-2, -2) (quadrant 3)
p1+p2: (-1, -1) (quadrant 3)
The distance between (1, 1) and (-2, -2) is 4.242640687119285
Here is the Point class
package pointapp;
import java.util.Scanner;
public class Point {
private int x;
private int y;
public Point(int paramInt1, int paramInt2) {
x = paramInt1;
y = paramInt2;
}
public Point() {
this(0, 0);
}
public Point add(Point paramPoint) {
return new Point(x + x, y + y);
}
public double distance(Point paramPoint) {
return Math.sqrt(Math.pow(x - x, 2.0D) + Math.pow(y - y, 2.0D));
}
public Point xReflection() {
return new Point(x, -y);
}
public Point yReflection() {
return new Point(-x, y);
}
public Point originReflection() {
return new Point(-x, -y);
}
public int quadrant() {
return x < 0 ? 3 : y > 0 ? 2 : x > 0 ? 4 : y > 0 ? 1 : 0;
}
public boolean equals(Point paramPoint) {
return (x == x) && (y == y);
}
@Override
public String toString() {
return "(" + x + ", " + y + ")";
}
public static Point read(Scanner paramScanner) {
if (!paramScanner.hasNext()) {
return null;
}
int i = paramScanner.nextInt();
int j = paramScanner.nextInt();
return new Point(i, j);
}
public static final Point ORIGIN = new Point();
}
FILE points.text CONTAINS:
0 0 1 1
1 1 1 -1
1 1 -1 1
1 1 -1 -1
0 0 0 0
1 1 1 1
1 1 -2 -2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

Do you favor a civil service system? Why or why not?

Answered: 1 week ago