-4

Im trying to get the numbers in the object but instead im getting the address example:

_cityCenter = new Point (centerX , centerY);

how to get the centerX , centerY value? I want to get the numbers 5 , 10 for example and instead im getting Point@251221E Thanks in advance.

Daniel
  • 97
  • 10
  • (1-) To learn how to use any object you need to read the API for the `Point` object to find out how to access its properties (ie. the x and y values). – camickr Nov 13 '18 at 21:32
  • [`getX()`](https://docs.oracle.com/javase/7/docs/api/java/awt/Point.html#getX()) and `getY()` Javadoc exists for a reason ;) – Matt Clark Nov 13 '18 at 21:33

3 Answers3

0

_cityCenter.getX() , _cityCenter.getY()?

  • (1-) Although this may answer the question it does not help the OP with solving problems in the future. The OP has no idea where you cam up with those method names. If people want to program they need to know how to read the API. – camickr Nov 13 '18 at 21:36
  • I stand corrected @camickr thanks. – Liad Saubron Nov 13 '18 at 21:40
  • Also note that since x and y are specified as public in the API, then _cityCenter.x and _cityCenter.y will also work. – FredK Nov 13 '18 at 21:51
0

Depending on whether the access level modifier for centerX and centerY are public in the Point class, you can usually just do: _cityCenter.centerX to get the X coordinate and _cityCenter.centerY to get the Y coordinate.

If the modifiers restrict access to the fields (private etc.) you need to either implement a method in the Point class that will return their values if it hasn't already been implemented.

If this isn't a class that you created, there should be documentation showing the available methods.

0

You can access from 2 ways. In your Point class you must to have this if you wanna treat these numbers

public int getCenterX(){
   return centerX;
}

 public int getCenterY(){
   return centerY;
}

And then

_cityCenter.getCenterX();
_cityCenter.getCentery();

Each one is gonna return each point or override your toString method if you just wanna see them

@Override
public String toString() {
    return "Point [centerX=" + centerX + ", centerY=" + centerY + "]";
}
Jose O
  • 24
  • 2