Write an interface called Moveable with four void methods mo

Write an interface called Moveable with four void methods moveUp0, moveDown0, move Left() and moveRight(). Write a class called MoveablePoint that implements the Moveable interface above. This class contains two int fields x and y. Write the constructors, accessors and mutators, toString method and an \"equals\" inherited from Object class) method that compares the states of its objects. Write another class called MoveableCircle that extends the MoveablePoint. The x and y fields represent the center of the circle and have an int variable called radius. Write the constructors, accessors and mutators, toString method, \"equals\" method and a method called area that prints the area of the circle. Write a client class that creates one object of MoveablePoint and one object of MoveableCircle class. Test the moyeU moveDown0, moveLefto, moveRight0 methods for each object and print the object with each move. Also use the \"equals method to compare different objects and print out the results of the comparison. Call the area method on the objects of class MoveableCircle.

Solution

1.Interface Moveable :-

Interface Moveable
{
public void moveUp();
public void moveDown();
public void moveLeft();
public void moveRight();
}

2.Class MoveablePoint :-

public class MoveablePoint implements Moveable
{
int x;
int y;
MoveablePoint()
{
System.out.println(\"constructor\");
}
public void moveUp()
{
System.out.println(\"moveUp\");
}
public void moveDown()
{
System.out.println(\"moveDown\");
}
public void moveLeft()
{
System.out.println(\"moveLeft\");
}
public void moveRight()
{
System.out.println(\"moveRight\");
}
}

3.Class MoveableCircle :-

public class MoveableCircle extends MoveablePoint
{
int radius;
MoveableCircle()
{
System.out.println(\"constructor\");
}
}

4. Class Client :-

Public class Client
{
public static void main(String[] args)
{
MoveablePoint obj1 = new MoveablePoint();
MoveableCircle obj2 = new MoveableCircle();

obj1.moveUp();
obj1.moveDown();
obj1.moveLeft();
obj1.moveRight();

obj2.moveUp();
obj2.moveDown();
obj2.moveLeft();
obj2.moveRight();
}
}

 Write an interface called Moveable with four void methods moveUp0, moveDown0, move Left() and moveRight(). Write a class called MoveablePoint that implements t
 Write an interface called Moveable with four void methods moveUp0, moveDown0, move Left() and moveRight(). Write a class called MoveablePoint that implements t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site