Start New Discussion within our Software Development Community
import static java.lang.System.*;
public class ShipTester
{
    public static void main (String []args)
    {
        Ship s1 = new Ship();
        s1.setX(3);
        s1.setY(10);
        s1.setSPeed(22);
        out.println(s1.getX());
        out.println(s1.getY());
        out.println(s1.getSpeed());
        out.println(s1);//calls the ToString method
        Ship s2 = new Ship (3,10, 22);
        ship s3 = new Ship(5,7 );
        s3.setSpeed(19);
        out.println(s1.equals(s2));//s2 becomes rhs
        out.println(s1.equals(s3));//s3 becomes rhs
    }
}
public class Ship
{
    private int x,y, speed;
    public Ship()
    {
        x=y=speed=0;
    }
    public Ship(int xx,int yy)
    {
        x=xx;
        y=yy;
        speed=0;
    }
    public Ship(int xx,int yy,int sp)
    {
        x=xx;
        y=yy;
        speed=sp;
    }
    public int getX(){return x;}
    public int getY(){return y;}
    public int getSpped(){return speed;}
    public void setX(int x){xx == x;}
    public void setY(int y){yy== y;}
    public void setSpeed(int sp){speed= sp;}
    public boolean equals(Ship rhs)//rhs=right hand side
    {
        if(x==rhs.x&&y==rhs.y&&speed==rhs.speed)
        return true;
        return false;
    }
    public String toString()
    {
        return x +", "+y+", " = speed;
    }
}        // put your code here

it says those red lettered ones are not a statement.
what's wrong with those?

The way you are assiging is incorrect as what you are trying to do is evaluate whether xx==x; which is a like used for conditions.

For you to assign the value use only one "="
ex : xx=x;

However i doubt it would work as there are no class variables as xx I think what you are trying to do is something like below

public void setX(int x){this.x = x;}
public void setY(int y){this.y = y;}
This article has been dead for over six months. Start a new discussion instead.