class Postion{
private  int  X;     //定义变量
private  int  Y;     //定义变量
  
  Position(int x,int y){          //构造函数
   X=x;
   Y=y;  
   }
  
  public int GetX(){
   return  X;
   }
  public int GetY(){
   return  Y;
   } 
  
  public double distance(Position a, Position b){
   double m;
  
   m=Math.sqrt((a.GetX()-b.GetX())*(a.GetX()-b.GetX())+(a.GetY()-b.GetY())*
     (a.GetY()-b.GetY()));
     return m;
   }
}class  Result{
public static void main(String args[]){
Postion source=new Postion(0,0);
Postion target=new Postion(5,8);

int x1,x2,y1,y2;
double dis;
x1=source.GetX();
y1=source.GetY();
x2=target.GetX();
y2=target.GetY();

System.out.println("source is x1="+x1+"source is y1="+y1);
System.out.println("target is x2="+x2+"target is y2="+y2);

dis=source.distance(source,target);

System.out.println("the distance is:"+dis);
}
}//我觉得没有错误,编译老是告诉我对象加点不能调用,请大家帮忙看看,到底怎么回事?

解决方案 »

  1.   

    老大,position定义的时候少了个字母i
      

  2.   

    我知道了,Position写错了,下次一定小心。
      

  3.   


    public class Point { private int x; private int y; public Point(int x, int y) { // 构造函数
    this.x = x;
    this.y = y;
    } /**
     * @return Returns the x.
     */
    public int getX() {
    return x;
    } /**
     * @param x
     *            The x to set.
     */
    public void setX(int x) {
    this.x = x;
    } /**
     * @return Returns the y.
     */
    public int getY() {
    return y;
    } /**
     * @param y
     *            The y to set.
     */
    public void setY(int y) {
    this.y = y;
    } public double distance(Point a, Point b) {
    double offX = a.x - b.x;
    double offY = a.y - b.y; return Math.sqrt(offX * offX +offY * offY); } public static void main(String args[]) {
    Point source = new Point(0, 0);
    Point target = new Point(5, 8); int x1, x2, y1, y2;
    double dis;
    x1 = source.getX();
    y1 = source.getY();
    x2 = target.getX();
    y2 = target.getY(); System.out.println("source is x1=" + x1 + "source is y1=" + y1);
    System.out.println("target is x2=" + x2 + "target is y2=" + y2); dis = source.distance(source, target); System.out.println("the distance is:" + dis);
    }
    }
      

  4.   

    楼主的变量命名不符合java规则