JAVA - Please follow ALL instructions, thank you!! Here is the API, for a Point
ID: 3724910 • Letter: J
Question
JAVA - Please follow ALL instructions, thank you!!Here is the API, for a Point class representing a 2-dimensional point. https://docs.oracle.com/javase/7/docs/api/java/awt/Point.html
Code an application 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, exactly as shown below:
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
JAVA - Please follow ALL instructions, thank you!!
Here is the API, for a Point class representing a 2-dimensional point. https://docs.oracle.com/javase/7/docs/api/java/awt/Point.html
Code an application 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, exactly as shown below:
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
JAVA - Please follow ALL instructions, thank you!!
Here is the API, for a Point class representing a 2-dimensional point. https://docs.oracle.com/javase/7/docs/api/java/awt/Point.html
Code an application 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, exactly as shown below:
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
Explanation / Answer
import java.io.*;
import java.util.*;
import java.lang.*;
public class PointApp{
public static void main(String[] args) throws Exception
{
Scanner scanner = new Scanner(new File("test.txt"));
int [] tall = new int [100];
int i = 0;
while(scanner.hasNextInt())
{
int x1= scanner.nextInt();
int y1= scanner.nextInt();
int x2= scanner.nextInt();
int y2= scanner.nextInt();
//System.out.println(x1+" "+y1+" "+x2+" "+y2);
int k = cord(x1,y1);
int l = cord(x2,y2);
int sum = cord(x1+x2,y1+y2);
System.out.println("P1("+x1+","+y1+")(quadrant "+k+")"+"P2("+x2+","+y2+")(quadrant "+l+")");
System.out.println("P1+P2:("+(x1+x2)+","+(y1+y2)+")(quadrant "+sum+")");
if(x1==x2)
System.out.println("P1 and P2 are reflections across the x-axis");
if(y1==y2)
System.out.println("P1 and P2 are reflections across the y-axis");
if(x1==(-1*x2) && y1==(-1*y2))
System.out.println("P1 and P2 are reflections through the origin");
if(x1!=x2 && y1!=y2)
if(Math.abs(x1-0)==Math.abs(x2-0) && Math.abs(x1-0)==Math.abs(x2-0))
System.out.println("P1 and P2 are equidistant from the origin");
double d = dist(x1,y1,x2,y2);
System.out.println("distance between P1 and P2 is "+d + " ");
}
}
public static int cord(int x, int y){
int k=0;
if(x>=0){
if(y>=0)
return 1;
else
return 4;
}
if(x<0){
if(y>=0)
return 2;
else
return 3;
}
return -1;}
public static double dist(int x1, int y1, int x2, int y2){
double i = Math.pow(x2-x1,2);
double j = Math.pow(y2-y1,2);
double v = Math.sqrt((i+j));
return v;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.