Question: 3. (35 pts) Suppose you have an interface representing things that can be drawn on the screen in a drawing application: public interface Shape

3. (35 pts) Suppose you have an interface representing things that can be drawn on the screen in a drawing application: public interface Shape { } double getArea(); String getLabel (); void draw(); There may be many classes that implement the interface, such as Circle or Square, which are available to you as examples, along with the shape interface. Note that Circle has the constructor: public Circle (double x, double y, double radius, String givenLabel) // x, y is the center and square has the constructor public Square (double x, double y, double size, String givenLabel) // size is the length of each side Your task is to define a class Picture that keeps track of a list of shapes. It should have a no- argument constructor and the four methods: Methods and descriptions of class Shape void addShape (Shape s) adds the given shape to the picture, but throws an IllegalArgumentException if the shape has zero area double findTotalArea () returns the total area of all shapes added to the picture void undo () removes the most recently added shape ArrayList getLabels () returns a list of string containing the labels for all shapes in the picture Complete the class Picture below. import java.util.ArrayList; public class Picture { // TODO: add a no-argument constructor and the four methods here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
