Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are given. class BasicGLib { /** draw a circle of color c with center at current cursor position, the radius of the circle is
You are given. class BasicGLib { /** draw a circle of color c with center at current cursor position, the radius of the circle is given by radius */ public static void drawCircle(Color c, int radius) {/*...*/} ** draw a rectangle of Color c with lower left corner at current cursor position. * The length of the rectangle along the x axis is given by xlength. the length along they axis is given by ylength */ public static void drawRect(Color c, int xlength, int ylength) {/*...*/} ** move the cursor by coordinate (xcoord,ycoord) */ public static void moveCursor(int xcoord, int ycoord) {/*...*/} /** clear the entire screen and set cursor position to (0,0) */ public static void clear() {/*...*/} For example: BasicGLib.clear(); // initialize BasicGLib.drawCircle(Color.red, 3); // a red circle: radius 3, center (0,0) BasicGLib.drawRect(Color.blue, 3, 5); / / a blue rectangle: (0,0),(3,0),(3,5),(0,5)BasicGLib.moveCursor(2, 2); // move cursor BasicGLib.drawCircle(Color.green, 3); // a green circle: radius 3, center (2,2) BasicGLib.drawRect(Color.pink, 3, 5); // a pink rectangle: (2,2), (5,2),(5, 7),(2,7) BasicGLib.moveCursor(-2, -2); // move cursor back to (0,0) class Circle implements Shape { private int _r; public Circle(int r) { _r = r; } public void draw(Color c) { BasicGLib.drawCircle(c, _r); } class Rectangle implements Shape { private int _x, _y; public Rectangle(int x, int y) {_x = x; _y = y; } public void draw(Color c) { BasicGLib.drawRect(c, _x, _y); } You will write code to build and manipulate complex Shape objects built out of circles and rectangles. For example, the following client code:ComplexShape o = new ComplexShape(); o.addShape(new Circle(3) ); o.addShape(new Circle(5) ); ComplexShape o1 = new ComplexShape(); 01.addShape(o); 01.addShape(new Rectangle(4,8)); 01.draw(); builds a (complex) shape consisting of: a complex shape consisting of a circle of radius 3, a circle of radius 5 a rectangle of sides (3,5) Your task in this question is to finish the code for ComplexShape (add any instance variables you need) class ComplexShape implements Shape { public void addShape(Shape s) { } public void draw(Color c) { }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started