Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the JAVA program: Code an application class (i.e., a class containing a main method), named PointApp that reads point data from the file points.text.

Write the JAVA program:

Code an application class (i.e., a class containing a main method), 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.txt 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 

The Point Class:

import java.util.Scanner; public class Point { private int x; private int y; public static final Point ORIGIN = new Point(); public Point(int var1, int var2) { this.x = var1; this.y = var2; } public Point() { this(0, 0); } public Point add(Point var1) { return new Point(this.x + var1.x, this.y + var1.y); } public double distance(Point var1) { return Math.sqrt(Math.pow((double)(this.x - var1.x), 2.0D) + Math.pow((double)(this.y - var1.y), 2.0D)); } public Point xReflection() { return new Point(this.x, -this.y); } public Point yReflection() { return new Point(-this.x, this.y); } public Point originReflection() { return new Point(-this.x, -this.y); } public int quadrant() { return this.x > 0 ? (this.y > 0 ? 1 : 4) : (this.x < 0 ? (this.y > 0 ? 2 : 3) : 0); } public boolean equals(Point var1) { return this.x == var1.x && this.y == var1.y; } public String toString() { return "(" + this.x + ", " + this.y + ")"; } public static Point read(Scanner var0) { if (!var0.hasNext()) { return null; } else { int var1 = var0.nextInt(); int var2 = var0.nextInt(); return new Point(var1, var2); } } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions