prelim3Spring2006

# prelim3Spring2006 - Cornell net id Name CS 100J Prelim 3 18...

This preview shows pages 1–3. Sign up to view the full content.

Cornell net id ____________________ Name ________________________________ 1 CS 100J Prelim 3 18 April 2006 This 90-minute exam has 6 questions (numbered 0. .5) worth a total of 100 points. Spend a few minutes looking at all questions before answering any. Budget your time wisely. Use the back of the pages, if you need more space. We have a stapler at the front of the room, so you can tear the pages apart. Question 0 (2 points). Write your netid and your name, legibly, at the top of each page (Hint: do it now). Question 1 (15 points). Recursion. In assignment A2, you implemented a class Rhino that had, among other things, the fields shown in the partially completed class Rhino shown below. Write recursive function numberAncestors , whose specification and heading appear in the class below. Writing a loop is inappropriate and will cause many points to be deducted. Here’s what an ancestor is: an ancestor of a rhino is a (non-null) father or mother, or a (non-null) grandfather or grandmother, or …, etc. Don’t write any other methods; just write the body of numberAncestors . /** An instance describes a rhino.*/ public class Rhino { private String name; // The name of the rhino. private boolean gender; // = “this rhino is female” private Rhino father; // This rhino's father (null if unknown) private Rhino mother; // This rhino's mother (null if unknown) /** = the number of known ancestors of Rhino r. Precondition: r is not null */ public static int numberAncestors(Rhino r) { } } 0 ___________ out of 02 1 ___________ out of 15 2 ___________ out of 18 3 ___________ out of 20 4 ___________ out of 25 5 ___________ out of 20 Total ________ out of 100

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Cornell net id ____________________ Name ________________________________ 2 Question 2 (18 points). GUIs. Consider class GUI on the right, which, for the pur-
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

prelim3Spring2006 - Cornell net id Name CS 100J Prelim 3 18...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online