Question

JAVA - Please follow ALL instructions, thank you!! Here is the API, for a Point class...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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 + "\n");

}

}

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;

}

}

Add a comment
Know the answer?
Add Answer to:
JAVA - Please follow ALL instructions, thank you!! Here is the API, for a Point class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • INSTRUCTIONS: I NEED TO CREATE A PointApp PROGRAM THAT USES THE FOLLOWING API DOCUMENTATION. Below the...

    INSTRUCTIONS: I NEED TO CREATE A PointApp PROGRAM THAT USES THE FOLLOWING API DOCUMENTATION. Below the API Documentation is the code I submitted. However, the output is different for what they are asking. I am looking for someone to fix the code to print out the correct output and to add comments so I can have an idea in how the code works. PLEASE AND THANK YOU. API DOCUMENTATION: public class Point extends java.lang.Object The Point class is used to...

  • Java Help 2. Task: Create a client for the Point class. Be very thorough with your...

    Java Help 2. Task: Create a client for the Point class. Be very thorough with your testing (including invalid input) and have output similar to the sample output below: ---After declaration, constructors invoked--- Using toString(): First point is (0, 0) Second point is (7, 13) Third point is (7, 15) Second point (7, 13) lines up vertically with third point (7, 15) Second point (7, 13) doesn't line up horizontally with third point (7, 15) Enter the x-coordinate for first...

  • Create a MyPoint class to model a point in a two-dimensional space. The MyPoint class contains:...

    Create a MyPoint class to model a point in a two-dimensional space. The MyPoint class contains: • Two data fields x and y that represent the coordinates. • A no-arg constructor that creates a point (0,0). • A constructor that constructs a point with specified coordinates. • Two get functions for data fields x and y, respectively. • Two set functions for data fields x and y, respectively. • A function named distance that returns the distance from this point...

  • Please follow all the instructions and do all the parts (a-d)! Create a Java program which implem...

    Please follow all the instructions and do all the parts (a-d)! Create a Java program which implements Dijkstra’s shortest path algorithm according to the psueudocode below. Base the design on the weighted graph implementation used in Problem3.java (provided at the bottom). Your program should include the following features: a. A new method receives a starting vertex index and a target vertex index (e.g. 0 and 4). It computes the shortest distances to all vertexes using Dijkstra’s algorithm. The pseudocode is...

  •            1.         You often need to know the inheritance ____________________ of the Java API to work...

               1.         You often need to know the inheritance ____________________ of the Java API to work with its classes and subclasses.            2.         All objects have access to the methods of the ____________ class.            3.         If two classes share some common elements, you can define those elements in a ____________.            4.         To call a constructor or method of a superclass from a subclass, you use the ____________ keyword.            5.         A class that can be inherited by another...

  • JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate...

    JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate passing array reference to a method;        III. Demonstrate creating array of objects that prints out only x 0.0 for all objects. PROJECT 5C - ARRAYS Create a new file called " EventArray5C". There are some "challenging" directions in this project. . 1.Prepare a document box (tell me that task(s) the application is to accomplish, how it will accomplish the tasks, the author of...

  • Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in thr...

    Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and z. You will then use the class to perform some calculations on an array of these points. You need to draw a UML diagram for the class (Point3D) and then implement the class The Point3D class will have the...

  • Please help with program this. Thank you so much in advance! Create a Java program which...

    Please help with program this. Thank you so much in advance! Create a Java program which implements a simple stack machine. The machine has 6 instructions Push operand Puts a value on the stack. The operand is either a floating point literal or one of 10 memory locations designated MO M9 Pop operand Pops the value on the top of the stack and moves it to the memory location MO-M9 Add Pops the top two values off the stack, performs...

  • NEEDS TO BE IN PYTHON: (The Point class) Design a class named Point to represent a...

    NEEDS TO BE IN PYTHON: (The Point class) Design a class named Point to represent a point with x- and y-coordinates. The class contains: - Two private data fields x and y that represent the coordinates with get methods. - A constructor that constructs a point with specified coordinates, with default point (0, 0). - A method named distance that returns the distance from this point to another point of the Point type. - A method named isNearBy(p1) that returns...

  • Write a class called Point that contains two doubles that represent its x- and y-coordinates. It...

    Write a class called Point that contains two doubles that represent its x- and y-coordinates. It should have get and set methods for both fields. It should have a constructor that takes two double parameters and initializes its coordinates with those values. It should have a default constructor that initializes both coordinates to zero. It should also contain a method called distanceTo that takes as a parameter another Point and returns the distance from the Point that was passed as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT