eclipse - Java toString doesn't work -


this question has answer here:

i have got applikation in eclipse count rectangel, height, width points (p1,p2,p3,...,p10).

my points printed this:

point@659e0bfd, point@2a139a55, point@15db9742, point@6d06d69c, point@7852e922, point@4e25154f, point@70dea4e, point@5c647e05, point@33909752, point@55f96302 

could show me how should looks like? don't these tostring method. rest of code good?

    import java.util.arraylist; import java.util.list;  public class app {      //new public class app       public static void main(string[] args) {          point p1 = new point(10.681,-48.857);   // new points (x,y)         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 , 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);          public string tostring() {             return point;          }          new boundingbox(list1);         double c = boundingbox.height();         double d = boundingbox.width();          system.out.println("das array beinhaltet die punkte" + list1 ); // prints: "das array beinhaltet die punkte" , list         system.out.println("die boundingbox hat die hohe " + c + " und die breite " + d + "\n" );   // prints height , width         system.out.println("der maximale punkt der bbox betragt (" + boundingbox.getmaxpoint() +")." ); // prints:         system.out.println("der minimale punkt der bbox betragt (" + boundingbox.getminpoint() +")." ); // prints:       } } 

boundingbox

import java.util.list;  public class boundingbox {      //new class boundingbox private static point minpoint;      //new  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();      (int = 0; < 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 = (maxpoint.getx() - minpoint.getx());     // calculate width     return a; }  public static double height() {     double b = (maxpoint.gety() - minpoint.gety());     // calculate width     return b; }  public static point getmaxpoint() {     return maxpoint; }  public static point getminpoint() {     return minpoint; }  } 

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; }     } 

you should override tostring in point class.

public class point {     ...     @override     public string tostring ()     {         return x + "," + y; // or whatever wish display     }     ... } 

oh, , it's not clear intended here in app class :

    public string tostring() {         return point;      } 

this shouldn't pass compilation. , unless trying print app instance, don't have override tostring of app.


Comments