CSE 1302C Midterm Exam_SU11.docx

advertisement
CSE 1302C Midterm Exam
6/6/2011
NAME:___________________________________
Note: this test has a FRONT AND BACK SIDE!
Question 1 (25 pts): Imagine we’re writing a kind of word game where we have a 2D array of characters
that is 100x100. As part of the game, we must ensure that the letter ‘c’ does not appear more than 5
times in any column. If more than 5 c’s are present in any column, you should print out a message
informing us which column(s) have more than 5 (e.g. “Column 7 has more than 5 c’s”). Assuming that
the array – called “myArray” has already been declared and initialized, show the chunk of code that can
do this.
Question 2 (25 pts): Declare a List of integers. Then, add 500 numbers (of your choosing) to that list.
Question 3 (25 pts): Imagine that there is class called “Turtle” that has already been written - which has
a speed, color and name. Create a subclass 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 4 (25 pts): You’re sitting in your first job interview and are asked “Why is inheritance
necessary for polymorphism to work?” What would your answer be?
Download