Consider the Abstract SimpleMovingShape class that we developed previously. Comp
ID: 3713312 • Letter: C
Question
Consider the Abstract SimpleMovingShape class that we developed previously. Complete the SimpleMovingoval class. The SimpleMovingoval subclass contains . two overloaded constructors an overriding tostring() method that returns "Oval:" and the string returned from the toString() in the super class. . an overriding draw() method that outputs a string description of the instance in the format "oval (x-coordinate, y-coordinate) width x height" Write the simpleMovingOval class in the answer box below assuming that the abstract SimpleMovingShape class has been done for you in the Code Runner System. For example Test Result Oval: (0, 0), 0 x SimpleMovingoval c1new SimpleHovingoval) System.out.println (c1); | simplesovingoval(new Oval: (10, 20), 2a x 40 simpleMovingoval System.out.println(c3); c3 new Point(10, 20), 20, 40); =Explanation / Answer
//SimpleMovingShape.java
import java.awt.Point;
public abstract class SimpleMovingShape
{
protected Point point;
protected int width;
protected int height;
//constructor to set point ,width and heiht
//to zero,0
public SimpleMovingShape()
{
point = new Point(0, 0);
width = 0;
height = 0;
}
//constructor to set user given point, width and height values
public SimpleMovingShape(Point point, int width, int height)
{
this.point = point;
this.width = width;
this.height = height;
}
/**Override the toString method*/
public String toString() {
return String.format("(%d , %d), %d x %d",
(int)point.getX(),
(int)point.getY(),
width,height);
}
/**write a abstracat draw method*/
public abstract void draw();
}
------------------------------------------------------------------------------------
//SimpleMovingOval.java
import java.awt.Point;
public class SimpleMovingOval extends SimpleMovingShape
{
public SimpleMovingOval() {
super();
}
public SimpleMovingOval(Point point,int width,int height) {
super(point, width, height);
}
/**Override the toString method*/
public String toString() {
return "Oval: "+super.toString();
}
/**Override the draw() method*/
public void draw() {
System.out.printf("(%d , %d), %d x %d",
(int)point.getX(),
(int)point.getY(),
width,height);
}
}
------------------------------------------------------------------------------------
//SimpleTester.java
import java.awt.Point;
public class SimpleTester {
public static void main(String[] args) {
//Create a instance of default object
SimpleMovingOval c1=
new SimpleMovingOval();
//print c1
System.out.println(c1);
//create an instance of SimpleMovingOval with point ,width and height
SimpleMovingOval c3=new SimpleMovingOval(new Point(10,20), 20,40);
//print c3
System.out.println(c3);
}
}
------------------------------------------------------------------------------------
Sample Output:
Oval: (0 , 0), 0 x 0
Oval: (10 , 20), 20 x 40
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.