
Patrick B. answered 07/18/21
Math and computer tutor/teacher
interface Moveable
{
public void moveLeft();
public void moveRight();
public void moveUp();
public void moveDown();
public void display();
}
class Point implements Moveable
{
public static final int MAX_CHAR=200;
protected int x;
protected int y;
public Point(int X, int Y) { x=X; y=Y; }
public int GetX() { return(x); }
public int GetY() { return(y); }
Point(Point p) { this.x = p.x; this.y=p.y; } //copy constructor
//implements Moveable
public void moveLeft()
{
if (x>0)
{
x--;
}
else
{
System.out.println("BUMP:Bounces off left side");
}
}
public void moveRight()
{
if (x<Point.MAX_CHAR)
{
x++;
}
else
{
System.out.println("BUMP:Bounces off right side");
}
}
public void moveUp()
{
if (y>0)
{
y--;
}
else
{
System.out.println(" BUMP: Bounces off top ");
}
}
public void moveDown()
{
if (y<Point.MAX_CHAR)
{
y++;
}
else
{
System.out.println(" BUMP: Bounces off bottom");
}
}
@Override public String toString()
{
return(
new String("Point:(" +x + "," +y+")")
);
}
public void display()
{
System.out.println(toString());
}
}
/*****************************************************************************/
class Point implements Moveable
{
public static final int MAX_CHAR=200;
protected int x;
protected int y;
public Point(int X, int Y) { x=X; y=Y; }
public int GetX() { return(x); }
public int GetY() { return(y); }
Point(Point p) { this.x = p.x; this.y=p.y; } //copy constructor
//implements Moveable
public void moveLeft()
{
if (x>0)
{
x--;
}
else
{
System.out.println("BUMP:Bounces off left side");
}
}
public void moveRight()
{
if (x<Point.MAX_CHAR)
{
x++;
}
else
{
System.out.println("BUMP:Bounces off right side");
}
}
public void moveUp()
{
if (y>0)
{
y--;
}
else
{
System.out.println(" BUMP: Bounces off top ");
}
}
public void moveDown()
{
if (y<Point.MAX_CHAR)
{
y++;
}
else
{
System.out.println(" BUMP: Bounces off bottom");
}
}
@Override public String toString()
{
return(
new String("Point:(" +x + "," +y+")")
);
}
public void display()
{
System.out.println(toString());
}
}
/*********************************************************************************************************/
class Point implements Moveable
{
public static final int MAX_CHAR=200;
protected int x;
protected int y;
public Point(int X, int Y) { x=X; y=Y; }
public int GetX() { return(x); }
public int GetY() { return(y); }
Point(Point p) { this.x = p.x; this.y=p.y; } //copy constructor
//implements Moveable
public void moveLeft()
{
if (x>0)
{
x--;
}
else
{
System.out.println("BUMP:Bounces off left side");
}
}
public void moveRight()
{
if (x<Point.MAX_CHAR)
{
x++;
}
else
{
System.out.println("BUMP:Bounces off right side");
}
}
public void moveUp()
{
if (y>0)
{
y--;
}
else
{
System.out.println(" BUMP: Bounces off top ");
}
}
public void moveDown()
{
if (y<Point.MAX_CHAR)
{
y++;
}
else
{
System.out.println(" BUMP: Bounces off bottom");
}
}
@Override public String toString()
{
return(
new String("Point:(" +x + "," +y+")")
);
}
public void display()
{
System.out.println(toString());
}
}
//********** Here is the inheritance exercise that you posted earlier on today ********************//
abstract class Shape2D
{
abstract public double Area();
abstract public double Perimeter();
}
class Circle extends Shape2D
{
protected double radius;
@Override public double Area()
{
return(Math.PI * radius*radius);
}
@Override public double Perimeter()
{
return(Math.PI * 2 * radius);
}
double GetRadius() { return(radius); }
Circle( double r) { radius=r; }
@Override public String toString()
{
return(
new String(" Cirlce radius = " + radius + "\n" +
" perimeter = " + Perimeter() + "\n" +
" area = " + Area() + "\n"
)
);
}
}
class Rectangle extends Shape2D
{
protected double length;
protected double width;
@Override public double Area()
{
return(length*width);
}
@Override public double Perimeter()
{
return(2*length+2*width);
}
double GetLength() { return(length); }
double GetWidth() { return(width); }
Rectangle( double l, double w) { length=l; width=w; }
@Override public String toString()
{
return(
new String(" Rectangle length = " + length + "\n" +
" width = " + width + "\n" +
" perimeter = " + Perimeter() + "\n" +
" area = " + Area() + "\n"
)
);
}
Jade Ruby T.
Hi, I dont understand how there's no Scanner07/19/21