Computer Math Test #5
List the three non-static methods in the Bucket class:
fill(); pourInto(); spill();
Use a for loop to create the following image. Each filled circle is 20 pixels across and the first circle on the left has an upper-left corner position of 100, 50.
for (int x=100; x<=180; x+=20) g.fillOval(x, 50, 20, 20);
Use a for loop to create the following image. Each line is 50 pixels long and 5 pixels apart. The top of the first line is at 80, 50.
for (int x=80; x<=115; x+=5) g.drawLine(x, 50, x, 100);
Draw a line connecting the points 20, 40 with 120, 80.
g.drawLine(20, 40, 120, 80);
Now draw that same ellipse except use 130, 90 as its center point.
g.drawOval(105, 47, 50, 85);
Draw an ellipse at position 130, 90 with a width of 50 and height of 85.
g.drawOval(130, 90, 50, 85);
Now draw that same circle except use 50, 100 as its center point.
g.drawOval(20, 70, 60, 60);
Draw a circle at position 40, 70 (position of top-left corner of imaginary rectangle in which the circle will be placed) with a width and height of 75.
g.drawOval(40, 70, 75, 75);
Draw a circle at position 50, 100 with a width and height of 60.
g.drawOval(50, 100, 60, 60);
Draw a Square whose top-left corner is at position 200, 150, and whose sides have a length of 100.
g.drawRect(200, 150, 100, 100);
Draw a Rectangle whose top-left corner is at position 50, 75 and whose width is 100 and height is 200.
g.drawRect(50, 75, 100, 200);
Using a Graphics object g, set the color to yellow.
g.setColor(Color.yellow);
Now set the color to a brighter yellow.
g.setColor(Color.yellow.brighter());
Now set the color to a darker yellow.
g.setColor(Color.yellow.darker());
And now black.
g.setColor(new Color(0, 0, 0));
And now set the color to blue.
g.setColor(new Color(0, 0, 255));
Do the same to set the color to green.
g.setColor(new Color(0, 255, 0));
Using the Graphics object g, use the 3-arg Color constructor to set the color to red.
g.setColor(new Color(255, 0, 0));
Do the same for white.
g.setColor(new Color(255, 255, 255));
Now set the font of the Graphics object g to f1.
g.setFont(f1);
Now set the font of the Graphics object g to f2.
g.setFont(f2);
Know how to get a certain amount of gallons from buckets of two different capacities.
ok
The Bucket class also contains two private fields. the first field, totalWater, is static, the second, water, is non-static. This means that if we create three Bucket objects, then _______ copy(ies) of the static field totalWater is(are) made, while _______ copy(ies) of the instance field water is(are) made.
one and three
How many pre-defined color are there in the Color class?
13
Why is setSpeed a static method?
Because when we setSpeed, we are setting all of the Buckets, NOT JUST ONE.
List the 13 colors in the Color class:
Black, blue, cyan, darkGray, gray, green, lightGray, magenta, orange, pink, red, white, yellow
Using the Font constructor, create a Font object called f1 with name "Serif", style bold, and size of 24.
Font f1 = new Font("Serif", Font.BOLD, 24);
Using the Font constructor, create a Font object called f2 with the name "Serif", style bold and italic, and size of 14.
Font f2 = new Font("Serif", Font.BOLD|Font.ITALIC, 14);
Given the following field declaration from the Bucket class: private static int totalWater; Explain what each word means.
Private: this field can only be used by members of the Bucket class. static: one copy of totalWater. int: integer. totalWater: a variable.
Use the drawPolygon method. Show the three lines of code necessary to create a triangle whose 3 points are (150, 50), (200, 150), (100, 150).
int xPoints[] = {150, 200, 100}; int yPoints[] = {50, 150, 150}; g.drawPolygon(xPoints, yPoints, 3);
A certain class has the declarations: public int instanceField; pubic static int staticField; If you instantiate three objects from this class, How many copies of instanceField do you have? How many copies of staticField do you have?
three and one