import java.awt.Color; public class DrawApp { private static int nCircles = 50; // main method public static void main(String[] args) { // Java provides a default constructor (no parameter version) // IF there is NO constructor at all // ERROR: non-default constructor exists in CircularStroke //CircularStroke csDefault = new CircularStroke(); //canvas.resize(400, 400); // create a Strokes array of size nCircles // use IS-A relationship // e.g.) CircularStroke IS-A Stroke, SquareStroke IS-A Stroke Stroke[] strokes = new Stroke[nCircles]; //strokes[0].draw(); int cx; int cy; int size = 10; Color c = Color.BLACK; boolean f = true; char choice = canvas.promptChar("Choose stroke type: C or S"); canvas.waitForUserClick(); for (int i = 0; i < nCircles; ++i) { //canvas.clear(); // sample mouse position cx = canvas.getMouseX(); cy = canvas.getMouseY(); Stroke stroke = null; // variable scope: only available/accessible within the closest enclosing { } if (choice == 'C' || choice == 'c') { stroke = new CircularStroke(cx, cy, size, f); } else { stroke = new SquareStroke(cx, cy, size, f); } stroke.draw(); strokes[i] = stroke; canvas.sleep(0.08); } canvas.waitForUserClick(); canvas.clear(); for (Stroke stroke : strokes) { stroke.draw(); } } }