use java programing Problem: Develop the ‘Shape’ application such that: • Implem
ID: 3572561 • Letter: U
Question
use java programing
Problem: Develop the ‘Shape’ application such that:
• Implement an array of objects of various types (all five classes), in any order.
• In some type of a looping structure, demonstrate polymorphism by calling all three of the methods, draw, move, and erase. That is, within the curly braces, there will be only three method calls.
• Verify that the output messages come from all three methods, from all seven classes.
The only class that you should have to develop for this class will be the test application. The seven classes from previous program should remain unchanged.
Explanation / Answer
ShapeTester.java (Test Program):
package shapetester;
public class ShapeTester {
public static void main(String[] args) {
Shape shapes[] = new Shape[5];
shapes[0] = new Rectangle();
shapes[1] = new Square();
shapes[2] = new Ellipse();
shapes[3] = new Circle();
shapes[4] = new Triangle();
// for each object in the array calling thier
// methods
for ( Shape s : shapes )
{
s.draw();
s.move();
s.erase();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.