class Point
{
int x,y;
String name="A point";
Point()
{
x=0;y=0;
}
Point(int x,int y,String name)
{
this.x=x;
this.y=y;
this.name=name;
}
int getX()
{
return x;
}
int getY()
{
return y;
}
void move(int newX,int newY)
{
x=newX;
y=newY;
}
Point newP(String name)
{
Point P=New Point(-x,-y,name);
return P;
}
boolean equal(int x,int y)
{
if(this.x==x&&this.y==y)
return true;
else
return false;
}
void print()
{
System.out.println(name+"x="+x+"y="+y);
}
}
public class UsingObject
{
public static void main(String args[])
{
Point P=new Point();
P.point();
P.move(50,50);
System.out.println("**after moving**");
System.out.println("Get x and y directly");
System.out.println("x="+P.x+"y="+P.y);
System.out.println("or Get x and y by calling method");
System.out.println("x="+P.getX()+"y="+P.getY());
if(P.equal(50,50))
System.out.println("I like this point!!!!");
else 
System.out.println("I hate it!!!!");
P.newPoint("A new point:").point();
newPoint(10,15,"Another new point").point();
}
}

解决方案 »

  1.   

    (1)Point P=New Point(-x,-y,name); //New应该为小写new
    (2)boolean equal(int x,int,y)   //int,y中间无逗号
    {
    if(this.x==x&&this.y==y)
    return true;
    else
    return false;
    }
    (3) Point P=new Point();
    p.point();//p为大写且没有point这个方法
    p.move(50,50);//p为大写(4) P.newPoint("A new point:").point();  //没有定义newPoint这个方法啊。
    newPoint(10,15,"Another new point").point();
    写程序的时候要细致,感觉都是不细致导致的问题。
      

  2.   

    --------------------Configuration: JDK version 1.4 <Default>--------------------
    C:\JCreator\MyProjects\Applet.java\UsingObject.java:40: <identifier> expected
    void()Point()
                ^
    C:\JCreator\MyProjects\Applet.java\UsingObject.java:44: '(' expected
    }
    ^
    C:\JCreator\MyProjects\Applet.java\UsingObject.java:50: cannot resolve symbol
    symbol  : method Point  ()
    location: class Point
    P.Point();
                     ^
    C:\JCreator\MyProjects\Applet.java\UsingObject.java:61: cannot resolve symbol
    symbol  : method Point  ()
    location: class Point
    P.newPoint("A new point:").Point();
                              ^
    C:\JCreator\MyProjects\Applet.java\UsingObject.java:62: cannot resolve symbol
    symbol  : method newPoint  (int,int,java.lang.String)
    location: class UsingObject
    newPoint(10,15,"Another new point").Point();
                    ^
    5 errorsProcess completed.
    还有这几个问题没有解决。
      

  3.   

    太粗心了,我大致改了一下,试试吧
    我看你不适合编程,变量名前后不一致,方法名前后不一致,错字一大堆class Point
    {
    int x,y;
    String name="A point";
    Point()
    {
    x=0;y=0;
    }
    Point(int x,int y,String name)
    {
    this.x=x;
    this.y=y;
    this.name=name;
    }
    int getX()
    {
    return x;
    }
    int getY()
    {
    return y;
    }
    void move(int newX,int newY)
    {
    x=newX;
    y=newY;
    }
    Point newP(String name)
    {
    Point P=new Point(-x,-y,name);
    return P;
    }
    boolean equal(int x,int y)
    {
    if(this.x==x&&this.y==y)
    return true;
    else
    return false;
    }
    void print()
    {
    System.out.println(name+"x="+x+"y="+y);
    }
    }
    public class UsingObject
    {
    public static void main(String args[])
    {
    Point p=new Point();
    p.print();
    p.move(50,50);
    System.out.println("**after moving**");
    System.out.println("Get x and y directly");
    System.out.println("x="+p.x+"y="+p.y);
    System.out.println("or Get x and y by calling method");
    System.out.println("x="+p.getX()+"y="+p.getY());
    if(p.equal(50,50))
    System.out.println("I like this point!!!!");
    else 
    System.out.println("I hate it!!!!");
    p.newP("A new point:").print();
    new Point(10,15,"Another new point").print();
    }
    }