In Java please! Output: The class Figure is an abstract base class. In this clas
ID: 3587404 • Letter: I
Question
In Java please!
Output:
The class Figure is an abstract base class. In this class, create abstract methods for draw, erase, center, equals, and toString Add Rectangle and Triangle classes derived from Figure. Each class has stubs for methods erase, draw, and center. In these "stubs, each method simply prints a message telling the name of the class and which method has been called in that class. Because these are just stubs, they do nothing more than output this message. The method center calls the erase and draw methods to erase the object at its current location and redraw the figure at the center of the picture being displayed. Because you have only stubs for erase and draw, center will not do any real "centering" but simply will call the methods erase and draw, which will allow you to see which versions of draw and center it calls. Add an output message in the method center that announces that center is being called. The methods should take no arguments. For a working system, you would have to replace the definition of each of these methods with code to do the actual drawing. You will be asked to do this in the next part of this homework Define a demonstration program for your classes which contains main. Test your programs: creating at least two Rectangle objects and two Triangle objects. o All instantiated classes have an equals and toString methods because these are abstract in the Figure class. o In this part of the homework, equals can simply return true, and toString can returns a String announcing that toString has been invoked . "draw" all of the objects you just created · "center" at least one Rectangle and one Triangle object In main, make sure that you tell the user what's going on at each step. For this part of the homework, do not submit any class listings. Instead, just submit the output of running your program. This should consist primarily of messages from your stub methods. An example of the output from your program might be the following (note: output from main methods is shown below in italics)Explanation / Answer
Note:bro i will complete it..have to add some more code...
package org.students;
public abstract class Figure {
public abstract void draw();
public abstract void erase();
public abstract void center();
public abstract boolean equals();
public abstract String toString();
}
________________
package org.students;
public class Triangle extends Figure {
@Override
public void draw() {
System.out.println("Entering draw() method for Triangle");
}
@Override
public void erase() {
System.out.println("Center() calling erase()");
}
@Override
public void center() {
System.out.println("Entering Center() method for Triangle");
}
@Override
public boolean equals() {
return true;
}
@Override
public String toString() {
return "toString has been invoked";
}
}
_________________
package org.students;
public class Rectangle extends Figure {
@Override
public void draw() {
System.out.println("Entering draw() method for Rectangle");
}
@Override
public void erase() {
System.out.println("Entering Center() method for Rectangle ");
}
@Override
public void center() {
System.out.println("Center() calling erase()");
}
@Override
public boolean equals() {
return true;
}
@Override
public String toString() {
return "toString has been invoked";
}
}
__________________
package org.students;
public class Test {
public static void main(String[] args) {
Rectangle r1=new Rectangle();
Rectangle r2=new Rectangle();
Triangle t1=new Triangle();
Triangle t2=new Triangle();
r1.draw();
r2.draw();
t1.draw();
t2.draw();
r1.center();
t1.center();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.