import geometry.*; import colors.*; import draw.*; // union of shapes interface iShape { double totalArea(); } // square class class Square implements iShape { Posn nw; int size; IColor color; Square(Posn nw, int size, IColor color) { this.nw = nw; this.size = size; this.color = color; } // methods // totalArea // tells the area of a square /* ...this.nw... -- Posn ...this.size... -- int ...this.color.. -- IColor */ double totalArea(){ return this.size * this.size; } boolean Draw(Canvas c){ return c.drawRect(this.nw, this.size, this.size, this.color); } } // Circle Class class Circle implements iShape { Posn center; int radius; IColor color; Circle(Posn center, int radius, IColor color) { this.center = center; this.radius = radius; this.color = color; } // methods // totalArea // computes the total area of a circle /* ...this.center... -- Posn ...this.radius... -- int ...this.color... -- IColor */ double totalArea(){ return Math.PI * (this.radius * this.radius); } boolean Draw(Canvas c){ return c.drawCircle(this.center, this.radius, this.color); } } // Combo Class class Combo implements iShape { iShape top; iShape bottom; Combo(iShape top, iShape bottom) { this.top = top; this.bottom = bottom; } // methods // totalArea // computes the total area of a combo /* ...this.top... -- iShape ...this.bottom... -- iShape */ double totalArea(){ return this.top.totalArea() + this.bottom.totalArea(); } } class Example{ Example() {} Posn posn1 = new Posn(100, 100); Posn posn2 = new Posn(150, 150); IColor red = new Red(); iShape square1 = new Square(this.posn1, 10, this.red); iShape circle1 = new Circle(this.posn2, 10, this.red); iShape combo1 = new Combo(this.square1, this.circle1); boolean testTotalArea = (check this.square1.totalArea() expect 100 within .01) && (check this.circle1.totalArea() expect 314.15 within .01)&& (check this.combo1.totalArea() expect 414.15 within .01); Canvas c = new Canvas(200, 200); boolean makeDrawing = this.c.show() && this.c.drawDisk(new Posn(100, 150), 50, new Red()); }