Computer Science 15-110, Lecture 9 (Sections M-Q), Fall 2009
Homework 2
Due: Thu 10-Sep-2009 at 11:59pm (email copy to your CA)
(no late submissions accepted).
Read these instructions first!
a) |
|
b) |
|
c) |
|
Note: some of these methods may seem a bit confusing, and in
fact they are! There are some much easier, clearer, and
more sensible ways to do the same thing. This is to test your
understanding of data and expressions, not to teach the best way to write
these methods.
public void mysteryPaintMethod(Graphics page, int left, int top, int width, int height) { page.setColor(Color.black); page.drawRect(left, top, width, height); int hWidth = width/4; int hHeight = height/5; page.setColor(Color.blue); page.fillOval(left+width/2-hWidth/2, top, hWidth, hHeight); top += hHeight; int bWidth = width/3; int bHeight = height/5*2; int bLeft = left+width/2-bWidth/2; page.setColor(Color.blue); page.fillRect(left, top+bHeight/4, width, bHeight/6); page.setColor(Color.red); page.fillRect(bLeft, top, bWidth, bHeight); page.setColor(Color.blue); top += bHeight; int lWidth = width/7; int lHeight = height/5*2; page.fillRect(bLeft, top, lWidth, lHeight); page.fillRect(bLeft+bWidth-lWidth, top, lWidth, lHeight); }
Carpe diem!