public void paint(Graphics page) { int x, y = 200; page.setColor(Color.blue); for(x = 100; x < 200; x += 20) page.fillRect(x, y, 10, y-x); }


Consider the following paint method and answer questions :


public void paint(Graphics page)

{

int x, y = 200;

page.setColor(Color.blue);

for(x = 100; x < 200; x += 20)

page.fillRect(x, y, 10, y-x);



1) This paint method will draw several bars (sort of like a bar graph). How many bars will be displayed?


a) 4

b) 5

c) 6

d) 10

e) 20

Answer: b. Explanation: Since x iterates from 100 up to 200 in units of 20, it iterates 5 times (x = 100, x = 120, x= 140, x = 160, x = 180).

2) The size of each rectangle (bar)


a) increases in height while staying the same width

b) increases in width while staying the same height

c) increases in both width and height

d) stays the same size

e) decreases in height while staying the same width

Answer: e. Explanation: The width is a constant 10. The height is y-x where x increases by 20 each iteration, so the height decreases by 20.