编写MyPoint.java,定义点的数据结构为两个双精度数[x,y]并重写toString方法,通过字符串连接运算,使输出点形式为:
start point is start[x,y]
end point is end[x,y]

解决方案 »

  1.   

    楼主什么意思啊,为什么一个点的输出形式是
    start point is start[x,y]...
    这个样子啊
      

  2.   

    说清楚你要干嘛阿,如果一个点是[100,100]
    难道toString 方法返回的是start point is start[100,100] 
    end point is end[100,100] 啊,这也太简单了吧,你不说清楚怎么帮阿
      

  3.   

    不太明白楼主的意思,不知道是不是这样的public class MyPoint
    {
      private double x;  private double y;  public MyPoint()
      {  }  public MyPoint(double x, double y)
      {
        this.x = x;
        this.y = y;
      }  public double getX()
      {
        return x;
      }  public void setX(double x)
      {
        this.x = x;
      }  public double getY()
      {
        return y;
      }  public void setY(double y)
      {
        this.y = y;
      }  public String toString()
      {
        return "[" + x + "," + y + "]";
      }  public static void main(String[] args)
      {
        System.out.println("start point is start" + new MyPoint(1.0, 1.0)
            + "\nend point is end" + new MyPoint(2.0, 2.0));
      }
    }
      

  4.   

    public class MyPoint
    {
    private double [] start = new double[2];
    private double [] end = new double[2];
    public MyPoint()
    {}
    public MyPoint(double startX,double startY,double endX,double endY)
    {
      this.start[0]=srtartX;
    this.start[1]=srtartY;
      this.end[0]=endX;
    this.end[1]=endY;
    }
    public String toString()
    {
     return "start point is start["+start[0]+","+start[1]+"]\n end point is end["+end[0]+","+end[1]+"]";
    }
    }
      

  5.   

    public class MyPoint{
    private double x = 0.0;
    private double y = 0.0;
    String name = "";
    public MyPoint(double x,double y,String name){
    this.x = x;
    this.y = y;
    this.name = name;
    }
    public String toString() {
    return name+ " point is "+name+"["+x+","+y+"]";
    }

    public static void main(String[] args) throws Exception {
    MyPoint start = new MyPoint(123,21,"start");
    MyPoint end = new MyPoint(123,21,"end");

    System.out.println(start);
    System.out.println(end);

    }
    }
      

  6.   

    package temporary;public class MyPoint { /**
     * @param args
     */
    public String toString(){
    StringBuffer result = new StringBuffer();
    if(pStart_End){
    result.append("start point is start");
    result.append("["+xCoordinate+","+yCoordinate+"]");
    }
    else{
    result.append("end point is end");
    result.append("["+xCoordinate+","+yCoordinate+"]");
    }
    return result.toString();

    }
    private double xCoordinate = 0;
        private double yCoordinate = 0;
        private boolean pStart_End = true;//每一个点都有肯能是起点或终点,他是一个相对的概念
        
        public MyPoint(double xCoordinate,double yCoordinate,boolean pStart_End){
         this.xCoordinate = xCoordinate;
         this.yCoordinate = yCoordinate;
         this.pStart_End = pStart_End;
        }
        
    public static void main(String[] args) {
    // TODO Auto-generated method stub MyPoint start = new MyPoint(1,2,true);
            MyPoint end = new MyPoint(3,4,false);
            
            System.out.println(start);
            System.out.println(end);
    }
    }