Hi, Please follow the instructions exactly. ONLY the main class needs to be writ
ID: 3725007 • Letter: H
Question
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
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
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 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
Explanation / Answer
There is some mistakes in Point.java file...
like 0,0 is quadrant 0, 1,1 also quadrant 0 mistake in output.
At finding distance paramPoint.x or paramPoint.y is missing like
Rectified Point.java attached at last
import java.io.*;
import java.util.*;
class PointApp {
public static void main(String args[]) {
try {
File file = new File("points.text");
Scanner in = new Scanner(new FileReader(file));
while(in.hasNextLine()){
Point p1 = Point.read(in);
Point p2 = Point.read(in);
Point p3 = p1.add(p2);
Point r_x = p1.xReflection();
Point r_y = p1.yReflection();
Point r_o = p1.originReflection();
System.out.print("p1: " + p1.toString() + " (quadrant " + p1.quadrant() + ")");
System.out.println(" / p2: " + p2.toString() + " (quadrant " + p2.quadrant() + ")");
System.out.println("p1 + p2: " + p3.toString() + " (quadrant " + p3.quadrant() + ")");
if (r_x.equals(p2))
System.out.println("p1 and p2 are reflections across the x-axis");
if (r_y.equals(p2))
System.out.println("p1 and p2 are reflections across the x-axis");
if (r_o.equals(p2))
System.out.println("p1 and p2 are reflections through the origin");
if (p1.distance(Point.ORIGIN) == p2.distance(Point.ORIGIN))
System.out.println("p1 and p2 are equidistant from the origin");
System.out.println("The distance between " + p1.toString() + " and " + p2.toString() + " is " + p1.distance(p2));
System.out.println(" ");
}
} catch (FileNotFoundException e) {
System.out.println("Error opening file");
}
}
}
//Point.java
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 + paramPoint.x, y + paramPoint.y);
}
public double distance(Point paramPoint) {
return Math.sqrt(Math.pow(paramPoint.x - x, 2.0D) + Math.pow(paramPoint.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() {
if(x<0 && y<0)
return 3;
else if(x>=0 && y>=0)
return 0;
else if(x<0 && y>0)
return 1;
else
return 2;
//return x < 0 ? 3 : y > 0 ? 2 : x > 0 ? 4 : y > 0 ? 1 : 0;
}
public boolean equals(Point paramPoint) {
return (x == paramPoint.x) && (y == paramPoint.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();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.