CSE 1302C Midterm 2/20/2012 Directions: You have 90 minutes to

advertisement
CSE 1302C Midterm
2/20/2012
Directions: You have 90 minutes to complete this exam. All answers are to be your own, without the
assistance of others. If you have a question, please raise your hand and the instructor will be with you shortly.
Question 1 (OOD): Imagine we are designing a game about Turtles and further imagine that we have the
(simplified) UML diagram below that describes a class hierarchy. Note that all Turtles have a weight and
rank, as well as the ability to move and attack. The two subclasses have overridden the appropriate methods.
For this question:

(10 pts) Give a quick definition of “inheritance” in programming.

(10 pts) Explain what it means to “override” a method as well as when you should do it.

(15 pts) Explain the term “polymorphism” as if to a programmer who isn’t familiar with the concept.

(15 pts) Give a coding example of polymorphism (not inheritance, or you’ll be wasting time…)
Question 2 (2D Arrays – 25 pts): We’ve talked about 2D arrays for storing 2D terrains – like in The Legend of
Zelda. To refresh your memory, we can store numbers in a 16x10 2D array – where the numbers represent
the terrain type (e.g. “sand” == 1, “rock”==2, “tree”==3, “grave”==4, etc…). Imagine we want to make
sure that a “grave” piece of terrain (#4) does not lie directly next to a “rock” piece of terrain (#2), like those
with the arrows pointing to them below; if a grave is next to a rock, the terrain is not “allowable”. Write a
function with the prototype (below) that determines whether or not a 2D array of ints violates this rule.
public boolean isGoodTerrain (int[,] terrainArray, int width, int height);
Hints: if you get rows vs. columns confused, I don’t care. Also, don’t check any terrain at the border of the
room. I don’t care about the diagonals; just check “North, South, East, West” for each terrain piece. Lastly,
how do you know if a terrain piece is a grave?
(“illegal” terrain pieces)
Question 3 (Collections – 25pts): Assume that you have the 2D array of ints called “terrainArray” from
above. Create a List of ints, then add all the data from the terrainArray into the List.
Download
Related flashcards
C software

30 Cards

Create flashcards