CSE 1302C Midterm Exam_FA10.docx

advertisement
CSE 1302C Midterm Exam
2/21/2011
Question 1 (25 pts): Suppose that there is a 1000x1000 2D array that is filled with values that represent
colors: 0=black, 1=blue, 2=green, 3=aqua, 4=red, 5=purple, 6=yellow, 7=white (aka “3-bit color”). The
array is called “myColorArray” and has already been initialized. Show the chunk of code that will print
out the percentage of each color (e.g. 21.2% black, 7% blue, 14.6% green, etc…).
Question 2 (25 pts): Imagine that there is class called “Turtle” that has already been written. Create a
class called “AttackTurtle” that has an additional attribute – number of missiles – and a new method
called “launch” that decrements the number of missiles by 1.
Question 3 (25 pts): What is inheritance? What is polymorphism? Give a brief example!
Question 4 (25 pts): Declare a List that can hold AttackTurtles. Then, create 100 AttackTurtles from
question 2 and add them to the list.
Download