CS110 Final Exam
Sample Exam
1. What was Java's original name? Who invented it? Who owns it?
2. What is the following called?
-
wet hair
-
apply shampoo
-
rub hair
-
rinse
-
repeat
3. What is OOP?
4. What are the steps to creating an applet?
5. Fill in the paint method in order to reproduce the following picture.
6. Fill in the paint method to draw a 8 x 8 checker board.
7. What does the following paint method draw?
public void paint(Graphics g) {
int x = 5;
int y = 10;
for (int i = 0; i < 5; i++) {
g.drawLine(x, y, x + 10, y * 2);
}
}
8. What is wrong with the following code? Mark each item with a number, and describe what is wrong in the space provided.
// File: Star.java
import java.awt.*;
import java.applet.Applet;
public class star extends Appelet {
int red, green, blue, x, y, w;
public void paint( Graphic g )
setBackground(Color.black);
g.setColor(Color.white);
Font f = new Font("Helvetica", Font.PLAIN, 9);
g.setFont(f);
g.drawString("Applet by Doug.", 1, 299)
for (int i = 0; i <= 100; i++) {
// get the coordinates, and size:
X = (int) (Math.random() * 300);
y = (int) (Math.random() * 299);
w = (int) (Math.random() * 10);
// pick a new color
red = (int) (Math.random()*256);
green = (int) (Math.random()*256);
blue = (int) (Math.random()*256);
g.setColor(new Color(red, green, blue));
g.fillOval(x, y, w, w);
}
}
}
}
Solution:
// File: Star.java
import java.awt.*;
import java.applet.Applet;
public class Star extends Applet {
int red, green, blue, x, y, w;
public void paint( Graphics g ) {
setBackground(Color.black);
g.setColor(Color.white);
Font f = new Font("Helvetica", Font.PLAIN, 9);
g.setFont(f);
g.drawString("Applet by Doug.", 1, 299);
for (int i = 1; i <= 100; i++) {
// get the coordinates, and size:
x = (int) (Math.random() * 300);
y = (int) (Math.random() * 300);
w = (int) (Math.random() * 10);
// pick a new color
red = (int) (Math.random()*256);
green = (int) (Math.random()*256);
blue = (int) (Math.random()*256);
g.setColor(new Color(red, green, blue));
g.fillOval(x, y, w, w);
}
}
}
9. Floats and ints 10. Equations and Java
11. Writing your own methods
public class ... {
public void mydrawArc(Graphics g, int xCenter, int yCenter, int radius, int startAngle, int stopAngle) {
g.drawArc(xCenter - radius, yCenter - radius, radius * 2, radius * 2, startAngle, stopAngle - startAngle );
}
public void paint(Graphics g) {
mydrawArc(g, 100, 100, 10, 45, 135);
}
}
12. Events for buttons and mouses
13. if, and switch
14. and, or, and not
15. random and Boolean
16. while, for, do
17. nested loops
18. Objects and classes - describe
Second Half
1. Objects
2. Arrays
3. GNU OS and Free Software
4. Graphics and polygons
5. Double Buffer and Threads
6. OO Design
7. Loops
8. Eliza and Strings
