I'm beginner with programming in Java. I would make an application to count max Point, min Point, width and height. I write in eclipse.
I become this error:
Exception in thread "main" java.lang.NullPointerException
at BoundingBox.height(BoundingBox.java:50)
at App.main(App.java:39)`
and my printed points looks like
Point#659e0bfd
Point#2a139a55
Point#15db9742
How should the method toString looks like in this code?
Point
public class Point {
private double x;
private double y;
public Point(double xnew, double ynew) {
x = xnew;
y = ynew;
}
public double getX() {
return x;
}
public void setX(double xnew) {
x = xnew;
}
public double getY() {
return y;
}
public void setY(double ynew) {
y = ynew;
}
}
BoundingBox
import java.util.List;
public class BoundingBox {
private static Point minPoint;
private static Point maxPoint;
public BoundingBox(List<Point> manyPoints) {
double minX = manyPoints.get(0).getX();
double maxX = manyPoints.get(0).getX();
double minY = manyPoints.get(0).getY();
double maxY = manyPoints.get(0).getY();
for (int i = 0; i < manyPoints.size(); i++) {
Point test = manyPoints.get(i);
test.getX();
if (test.getX() < minX) {
minX = test.getX();
}
if (test.getX() > maxX) {
maxX = test.getX();
}
if (test.getY() < minY) {
minY = test.getY();
}
if (test.getY() > maxY) {
maxY = test.getY();
}
minPoint = new Point(minX, minY);
maxPoint = new Point(maxX, maxY);
}
}
public static double width() {
double a = (maxPoint.getX() - minPoint.getX());
return a;
}
public static double height() {
System.out.println("minPoint = " + minPoint);
System.out.println("maxPoint = " + maxPoint);
double b = (maxPoint.getY() - minPoint.getY());
return b;
}
public Point getMaxPoint() {
return maxPoint;
}
public Point getMinPoint() {
return minPoint;
}
}
Application
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class App {
public static void main(String[] args) {
Point p1 = new Point(10.681,-48.857);
Point p2 = new Point(96.980,20.724);
Point p3 = new Point(66.647,-66.558);
Point p4 = new Point(-2.674,-58.571);
Point p5 = new Point(40.11,-12.342);
Point p6 = new Point(27.782,46.809);
Point p7 = new Point(54.759,-46.709);
Point p8 = new Point(-33.89,-90.787);
Point p9 = new Point(15.84,-67.553);
Point p10 = new Point(19.481,51.331);
List<Point> list1 = new ArrayList<Point>(); // Create ArrayList and add Points
list1.add(p1);
list1.add(p2);
list1.add(p3);
list1.add(p4);
list1.add(p5);
list1.add(p6);
list1.add(p7);
list1.add(p8);
list1.add(p9);
list1.add(p10);
Iterator<Point> itr = list1.iterator( );
while ( itr.hasNext( ) ) {
System.out.println( itr.next( ) );
}
double c = BoundingBox.height();
double d = BoundingBox.width();
System.out.println(" The Points: " + list1 );
System.out.println(" BoundingBox have " + c + "height and" + d + "width." );
System.out.println(" The max Point is " );
System.out.println(" The min Point is " );
}
}
Your variables:
private static Point minPoint;
private static Point maxPoint;
are initialized in BoundingBox constructor, but in your App you don't invoke it, so they are null. Just do the following:
new BoundingBox(list1);
double c = BoundingBox.height();
double d = BoundingBox.width();
and NullPointerException will disappear.
You never created an instance of the BoundingBox class before you tried to call the height() and width() functions so you're a receiving the null pointer exception on the line
double a = (maxPoint.getX() - minPoint.getX());
when it's trying to call maxPoint.getX() and minPoint.getX() since there's no values stored inside the variables
Related
I have written following Java code:
public class Point2D{
private double xc, yc;
public Point2D(double x, double y){
this.xc = x;
this.yc = y;
}
public Point2D createNewPoint(int xOff, int yOff){
this.xc = xc + xOff;
this.yc = yc + yOff;
return xc;
}
public static void main(String[] args){
Point2D p1 = new Point2D(2.5, 3.5);
Point2D p3 = p1.createNewPoint(5, -2);
System.out.println(p3);
}
}
I am getting following error:
Point2D.java:27: error: incompatible types: double cannot be converted to Point2D
return xc;
^
1 error
Can someone help me out to solve this error and also how to return two variables/values from a user-defined method in Java?
The type of the return value should match the return type. You have returned xc which is of type, double but the return type is Point2D.
Replace
public Point2D createNewPoint(int xOff, int yOff){
this.xc = xc + xOff;
this.yc = yc + yOff;
return xc;
}
with
public Point2D createNewPoint(int xOff, int yOff) {
return new Point2D(xc + xOff, yc + yOff);
}
Also, create a toString implementation something as shown below so that you can get a meaningful output when you print an object of Point2D.
public class Point2D {
private double xc, yc;
public Point2D(double x, double y) {
this.xc = x;
this.yc = y;
}
public Point2D createNewPoint(int xOff, int yOff) {
return new Point2D(xc + xOff, yc + yOff);
}
#Override
public String toString() {
return "Point2D [xc=" + xc + ", yc=" + yc + "]";
}
public static void main(String[] args) {
Point2D p1 = new Point2D(2.5, 3.5);
Point2D p3 = p1.createNewPoint(5, -2);
System.out.println(p3);
}
}
Add getters for the private fields
Return a new object, as shown in the solution below, from createNewPoint method if you want a new object
Use the getter methods to access the individual values.
class Point2D {
private double xc, yc;
public Point2D(double x, double y){
this.xc = x;
this.yc = y;
}
public Point2D createNewPoint(int xOff, int yOff){
return new Point2D(this.xc + xOff, this.yc + yOff);
}
public double getXc() {
return xc;
}
public double getYc() {
return yc;
}
public static void main(String[] args){
Point2D p1 = new Point2D(2.5, 3.5);
Point2D p3 = p1.createNewPoint(5, -2);
System.out.println (p3.getXc() + ":" + p3.getYc());
}
}
I'm trying to read coordinates from a file into an array.
Every coordinate has an id, an x-value and a y-value.
The file is in the following format: id position.x position.y
Example:
292961234 1376.42 618.056
29535583 3525.73 530.522
256351971 836.003 3563.33
20992560 4179.74 3074.27
Note: There are 4 lines containing a total of 4 coordinates.
I created the class Node and its constructor expects (int id, double x, double y).
And this is the class NodeList which is supposed to have an array attribute that saves the Nodes:
package .....;
import java.io.File;
import java.util.Iterator;
import java.util.Locale;
import java.util.Scanner;
public class NodeList implements Iterable<Node> {
private Node[] nodes = getNodes();
#Override
public Iterator<Node> iterator() {
return null;
}
public Node[] getNodes() {
Node[] result;
File f;
Scanner scanner;
try {
f = new File("nodes.txt");
Scanner s = new Scanner(f);
int ctr = 0;
while (s.hasNextLine()) {
ctr++;
s.nextLine();
}
result = new Node[ctr];
}
catch (Exception e) {
return null;
}
try {
scanner = new Scanner(f);
}
catch (Exception e) {
return null;
}
Locale.setDefault(new Locale("C"));
for(int i = 0; i < result.length; i++) {
int id = scanner.nextInt();
double x = scanner.nextDouble();
double y = scanner.nextDouble();
result[i] = new Node(id,x,y);
}
return result;
}
public static void main(String[] args) {
NodeList nl = new NodeList();
}
}
The Node class:
package ...;
public class Node {
private int id;
private double x;
private double y;
public Node(int id, double x, double y){
this.id = id;
this.x = x;
this.y = y;
}
public int getId(){
return id;
}
public double getX(){
return x;
}
public double getY(){
return y;
}
}
When the method containing the shown code is called, I get the following
Exception:
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
at ......NodeList.getNodes(NodeList.java:40)
at ......NodeList.<init>(NodeList.java:9)
at ......NodeList.main(NodeList.java:47)
Process finished with exit code 1
Link to the file containing the nodes: https://pastebin.com/zhzp3DTi
It might be that it is using wrong locale.
I don't think "C" is a valid locale, it should be a language code.
You can try to use
scanner.useLocale(Locale.ROOT);
This is working on my machine:
public static void main(String[] args) {
// TODO code application logic here
String s = "292961234 1376.42 618.056\n" +
"29535583 3525.73 530.522\n" +
"256351971 836.003 3563.33\n" +
"20992560 4179.74 3074.27";
Scanner scanner = new Scanner(s);
scanner.useLocale(Locale.ROOT);
for(int i = 0; i < 4; i++) {
int id = scanner.nextInt();
double x = scanner.nextDouble();
double y = scanner.nextDouble();
System.out.println(id+" "+x+" "+y);
}
}
I found the following code on the Internet. I think there is a problem in type conversion.
I tried to solving some of it but still there are few that elude me.
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Cluster {
public List points;
public Point centroid;
public int id;
//Creates a new Cluster
public Cluster(int id) {
this.id = id;
this.points = new ArrayList();
this.centroid = null;
}
public List getPoints() {
return points;
}
public void addPoint(Point point) {
points.add(point);
}
public void setPoints(List points) {
this.points = points;
}
public Point getCentroid() {
return centroid;
}
public void setCentroid(Point centroid) {
this.centroid = centroid;
}
public int getId() {
return id;
}
public void clear() {
points.clear();
}
public void plotCluster() {
System.out.println("[Cluster: " + id+"]");
System.out.println("[Centroid: " + centroid + "]");
System.out.println("[Points: \n");
for(Point p : points) {
System.out.println(p);
}
System.out.println("]");
}
}
public class Point {
private double x = 0;
private double y = 0;
private int cluster_number = 0;
public Point(double x, double y)
{
this.setX(x);
this.setY(y);
}
public void setX(double x) {
this.x = x;
}
public double getX() {
return this.x;
}
public void setY(double y) {
this.y = y;
}
public double getY() {
return this.y;
}
public void setCluster(int n) {
this.cluster_number = n;
}
public int getCluster() {
return this.cluster_number;
}
//Calculates the distance between two points.
protected static double distance(Point p, Point centroid) {
return Math.sqrt(Math.pow((centroid.getY() - p.getY()), 2) + Math.pow((centroid.getX() - p.getX()), 2));
}
//Creates random point
protected static Point createRandomPoint(int min, int max) {
Random r = new Random();
double x = min + (max - min) * r.nextDouble();
double y = min + (max - min) * r.nextDouble();
return new Point(x,y);
}
protected static List createRandomPoints(int min, int max, int number) {
List points = new ArrayList(number);
for(int i = 0; i < number; i++) {
points.add(createRandomPoint(min,max));
}
return points;
}
public String toString() {
return "("+x+","+y+")";
}
}
public class KMeans {
//Number of Clusters. This metric should be related to the number of points
private int NUM_CLUSTERS = 3;
//Number of Points
private int NUM_POINTS = 15;
//Min and Max X and Y
private static final int MIN_COORDINATE = 0;
private static final int MAX_COORDINATE = 10;
private List points;
private List clusters;
public KMeans() {
this.points = new ArrayList();
this.clusters = new ArrayList();
}
public static void main(String[] args) {
KMeans kmeans = new KMeans();
kmeans.init();
kmeans.calculate();
}
//Initializes the process
public void init() {
//Create Points
points = Point.createRandomPoints(MIN_COORDINATE,MAX_COORDINATE,NUM_POINTS);
//Create Clusters
//Set Random Centroids
for (int i = 0; i < NUM_CLUSTERS; i++) {
Cluster cluster = new Cluster(i);
Point centroid = Point.createRandomPoint(MIN_COORDINATE,MAX_COORDINATE);
cluster.setCentroid(centroid);
clusters.add(cluster);
}
//Print Initial state
plotClusters();
}
private void plotClusters() {
for (int i = 0; i < NUM_CLUSTERS; i++) {
Cluster c = clusters.get(i);
c.plotCluster();
}
}
//The process to calculate the K Means, with iterating method.
public void calculate() {
boolean finish = false;
int iteration = 0;
// Add in new data, one at a time, recalculating centroids with each new one.
while(!finish) {
//Clear cluster state
clearClusters();
List lastCentroids = getCentroids();
//Assign points to the closer cluster
assignCluster();
//Calculate new centroids.
calculateCentroids();
iteration++;
List currentCentroids = getCentroids();
//Calculates total distance between new and old Centroids
double distance = 0;
for(int i = 0; i < lastCentroids.size(); i++) {
distance += Point.distance(lastCentroids.get(i),currentCentroids.get(i));
}
System.out.println("#################");
System.out.println("Iteration: " + iteration);
System.out.println("Centroid distances: " + distance);
plotClusters();
if(distance == 0) {
finish = true;
}
}
}
private void clearClusters() {
for(Cluster cluster : clusters) {
cluster.clear();
}
}
private List getCentroids() {
List centroids = new ArrayList(NUM_CLUSTERS);
for(Cluster cluster : clusters) {
Point aux = cluster.getCentroid();
Point point = new Point(aux.getX(),aux.getY());
centroids.add(point);
}
return centroids;
}
private void assignCluster() {
double max = Double.MAX_VALUE;
double min = max;
int cluster = 0;
double distance = 0.0;
for(Point point : points) {
min = max;
for(int i = 0; i < NUM_CLUSTERS; i++) {
Cluster c = clusters.get(i);
distance = Point.distance(point, c.getCentroid());
if(distance < min){
min = distance;
cluster = i;
}
}
point.setCluster(cluster);
clusters.get(cluster).addPoint(point);
}
}
private void calculateCentroids() {
for(Cluster cluster : clusters) {
double sumX = 0;
double sumY = 0;
List list = cluster.getPoints();
int n_points = list.size();
for(Point point : list) {
sumX += point.getX();
sumY += point.getY();
}
Point centroid = cluster.getCentroid();
if(n_points > 0) {
double newX = sumX / n_points;
double newY = sumY / n_points;
centroid.setX(newX);
centroid.setY(newY);
}
}
}
}
I got the following erros. How to resolve them:
java:45: warning: [unchecked] unchecked call to add(E) as a member of the raw type List
clusters.add(cluster);
^
where E is a type-variable:
E extends Object declared in interface List
/tmp/java_kmNqUn/KMeans.java:54: error: incompatible types: Object cannot be converted to Cluster
Cluster c = clusters.get(i);
^
/tmp/java_kmNqUn/KMeans.java:84: error: incompatible types: Object cannot be converted to Point
distance += Point.distance(lastCentroids.get(i),currentCentroids.get(i));
^
/tmp/java_kmNqUn/KMeans.java:98: error: incompatible types: Object cannot be converted to Cluster
for(Cluster cluster : clusters) {
^
/tmp/java_kmNqUn/KMeans.java:105: error: incompatible types: Object cannot be converted to Cluster
for(Cluster cluster : clusters) {
^
/tmp/java_kmNqUn/KMeans.java:108: warning: [unchecked] unchecked call to add(E) as a member of the raw type List
centroids.add(point);
^
where E is a type-variable:
E extends Object declared in interface List
/tmp/java_kmNqUn/KMeans.java:119: error: incompatible types: Object cannot be converted to Point
for(Point point : points) {
^
/tmp/java_kmNqUn/KMeans.java:122: error: incompatible types: Object cannot be converted to Cluster
Cluster c = clusters.get(i);
^
/tmp/java_kmNqUn/KMeans.java:130: error: cannot find symbol
clusters.get(cluster).addPoint(point);
^
symbol: method addPoint(Point)
location: class Object
/tmp/java_kmNqUn/KMeans.java:135: error: incompatible types: Object cannot be converted to Cluster
for(Cluster cluster : clusters) {
^
/tmp/java_kmNqUn/KMeans.java:141: error: incompatible types: Object cannot be converted to Point
for(Point point : list) {
^
/tmp/java_kmNqUn/Point.java:61: warning: [unchecked] unchecked call to add(E) as a member of the raw type List
points.add(createRandomPoint(min,max));
^
where E is a type-variable:
E extends Object declared in interface List
/tmp/java_kmNqUn/Cluster.java:27: warning: [unchecked] unchecked call to add(E) as a member of the raw type List
points.add(point);
^
where E is a type-variable:
E extends Object declared in interface List
/tmp/java_kmNqUn/Cluster.java:54: error: incompatible types: Object cannot be converted to Point
for(Point p : points) {
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
10 errors
4 warnings*
please guide me...
You should avoid using a type List without any type parameters. You should instead use a List<SomeType> (replacing SomeType with the relevant type).
Using a strongly typed generic List with a type parameter is the best way of doing it. If, however, you are forced to use an older version of Java that does not support generics, you could cast the cluster objects like this: Cluster c = (Cluster)clusters.get(i);
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 8 years ago.
The Program I'm trying to make is supposed to draw a Polygon using points stored in an ArrayList. I rechecked the code and I am also using the driver, but when I try to run the program, it gives me a NullPointerException when I try to add coordinates for the program to use when drawing.
import java.awt.geom.*;
import java.util.ArrayList;
import gpdraw.*;
public class IrregularPolygon
{
private ArrayList <Point2D.Double> myPolygon;
DrawingTool myPen;
SketchPad myPaper;
double dblPerimeter;
double dblSegment;
double dblArea;
public IrregularPolygon()//Creating the sketchpad and pen
{
myPaper = new SketchPad(500,500);
myPen = new DrawingTool(myPaper);
}
public void add(Point2D.Double aPoint)//Adds to the array
{
myPolygon.add(aPoint);// This is where the problem is I think, I don't know what to do
}
public void draw()//This method draws the polygon
{
for(int x = 0; x < myPolygon.size() - 1 ; x++)
{
myPen.down();
myPen.move(myPolygon.get(x).getX(),myPolygon.get(x).getY());
myPen.up();
}
}
public double perimeter()//This method finds the perimeter
{
for(int x = 0; x < myPolygon.size() - 1; x++)
{
dblPerimeter += myPolygon.get(x).distance(myPolygon.get(x+1));
}
return dblPerimeter;
}
public double area()//This method finds the area
{
for(int x = 0; x < myPolygon.size() - 1; x++)
{
double X1 = (myPolygon.get(x).getX());
double Y1 = (myPolygon.get(x).getY());
double X2 = (myPolygon.get(x + 1).getX());
double Y2 = (myPolygon.get(x + 1).getY());
dblArea += (X1 * Y2 - Y1 * X2);
}
return dblArea;
}
}
and the programs runs from this driver:
import java.util.*;
import java.awt.geom.Point2D;
public class IrregularPolygonDriver
{
static boolean blnReadyToDraw = false;
static Scanner in = new Scanner(System.in);
public static void main(String[]args)
{
int num;
IrregularPolygon poly = new IrregularPolygon();
while(blnReadyToDraw == false)
{
System.out.println("Would you like to add a point, find the perimeter, or calculate the area?");
System.out.println("To add a point, enter 1; to find the perimeter, enter 2; to find the area, enter 3");
num = in.nextInt();
if(num == 1)
{
double dblNum1;
double dblNum2;
Point2D.Double dblNumber;
System.out.println("Enter an x value and a y value: ");
dblNum1 = in.nextDouble();
dblNum2 = in.nextDouble();
dblNumber = new Point2D.Double(dblNum1,dblNum2);
poly.add(dblNumber);
System.out.println("Keep adding points until you are done drawing the figure.");
}
else if(num == 2)
{
poly.perimeter();
}
else if(num == 3)
{
poly.area();
}
else
{
blnReadyToDraw = true;
System.out.println("Preparing to Draw");
}
}
poly.draw();
}
}
This is happening because your myPolygon is null.
Change:
private ArrayList <Point2D.Double> myPolygon;
To this:
private ArrayList <Point2D.Double> myPolygon = new ArrayList<>();
Or, in your constructor, add this line:
myPolygon = new ArrayList<>();
You didn't initialize your ArrayList,
private ArrayList <Point2D.Double> myPolygon;
is equivalent to
private ArrayList <Point2D.Double> myPolygon = null;
so when you say
myPolygon.add(aPoint); // <-- null.add(aPoint);
You could assign it in the constructor, or at declaration (using the List interface and the diamond operator <>) with something like
private List<Point2D.Double> myPolygon = new ArrayList<>();
I'm currently making an app for finding the roots of polynomials for android. At the moment I'm just dealing with quadratics however I can't spot my error. Whatever I've done it means my value for the root (only doing the first root right now), is always 0.0. Earlier I was trying to find my value for the discriminant and I kept getting the square of the 'b term' in the quadratic. My quadratic equation looks strange because of the way the application is set out, ever letter is shifted 1, so the closed form solution for quadratics in my app is -(c(+/-)(c^c-4*b*d)^(1/2))/(2*b). I would be grateful for any help, thanks! :)
P.S. Please try to ignore my awful code, I'm just trying to get it working at the moment :)
public void onButtonClick(View v)
{
double rx, ry, rz, disc, disc2, a, b, c, d;
String sa, sb, sc, sd, sx, sy, sz;
EditText ta = (EditText)findViewById(R.id.a_c);
EditText tb = (EditText)findViewById(R.id.b_c);
EditText tc = (EditText)findViewById(R.id.c_c);
EditText td = (EditText)findViewById(R.id.d_c);
EditText tx = (EditText)findViewById(R.id.x);
EditText ty = (EditText)findViewById(R.id.y);
EditText tz = (EditText)findViewById(R.id.z);
sa = ta.getText().toString();
sb = tb.getText().toString();
sc = tc.getText().toString();
sd = td.getText().toString();
sx = tx.getText().toString();
sy = ty.getText().toString();
sz = tz.getText().toString();
if(sa.matches("")) {a = 0;} else {a = Double.parseDouble(sa);}
if(sb.matches("")) {b = 0;} else {b = Double.parseDouble(sb);}
if(sc.matches("")) {c = 0;} else {c = Double.parseDouble(sc);}
if(sd.matches("")) {d = 0;} else {d = Double.parseDouble(sa);}
if(sx.matches("")) {rx = 0;} else {rx = Double.parseDouble(sx);}
if(sy.matches("")) {ry = 0;} else {ry = Double.parseDouble(sy);}
if(sz.matches("")) {rz = 0;} else {rz = Double.parseDouble(sz);}
disc2 = c*c-4*b*d;
if(a == 0) {rx = (-c+Math.sqrt(disc2))/(2*b); tx.setText(Double.toString(rx));}
}
Here's how I'd solve a quadratic equation. Sort this out first, then worry about getting data in and out:
/**
* Quadratic root finder
* #link http://stackoverflow.com/questions/23956437/quadratic-formula-in-java-for-android-cant-spot-my-mistake
*/
public class QuadraticRootFinder {
private static final double TOLERANCE = 1.0e-8;
public static void main(String[] args) {
if (args.length > 0) {
double a = Double.parseDouble(args[0]);
double b = ((args.length > 1) ? Double.parseDouble(args[1]) : 0.0);
double c = ((args.length > 2) ? Double.parseDouble(args[2]) : 0.0);
Complex [] roots = QuadraticRootFinder.getRoots(a, b, c);
for (Complex root : roots) {
System.out.println(root);
}
} else {
System.out.println("Usage: QuadraticRootFinder <a> <b> <c>");
}
}
public static Complex [] getRoots(double a, double b, double c) {
Complex [] roots = new Complex[2];
if (Math.abs(a) <= TOLERANCE) { // Linear equation; just one root
if (Math.abs(b) > TOLERANCE) {
roots = new Complex[1];
roots[0] = new Complex(-c/b);
} else {
throw new IllegalArgumentException(String.format("No roots possible for (a,b,c) = (%f10.3, %f10.3, %f10.3", a, b, c));
}
} else {
double discriminant = b*b-4.0*a*c;
if (discriminant > 0.0) { // Two real roots
roots[0] = new Complex(-b/2.0/a-Math.sqrt(discriminant)/2.0/a, 0.0);
roots[1] = new Complex(-b/2.0/a+Math.sqrt(discriminant)/2.0/a, 0.0);
} else { // Two complex conjugate roots
roots[0] = new Complex(-b/2.0/a, -Math.sqrt(-discriminant)/2.0/a);
roots[1] = new Complex(-b/2.0/a, +Math.sqrt(-discriminant)/2.0/a);
}
}
return roots;
}
}
class Complex {
private final double x;
private final double y;
Complex() {
this(0.0, 0.0);
}
Complex(double x) {
this(x, 0.0);
}
Complex(double x, double y) {
this.x = x;
this.y = y;
}
double getX() {
return x;
}
double getY() {
return y;
}
#Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("(").append(x).append(",").append(y).append(")");
return builder.toString();
}
}