prelim2fall2006 - Cornell net id _ Section day _ Name _...

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

View Full Document Right Arrow Icon
Cornell net id ____________________ Name ________________________________ Section day ______________________ Section time ___________________________ CS 100J Prelim 2 17 October 2006 Have a good break!!! This 90-minute exam has 6 questions (numbered 0. .5) worth a total of 100 points. Spend a few minutes looking at all ques- tions before beginning. Use the back of the pages, if you need more space. Question 0 (2 points). Fill in the information, legibly, at the top of each page (Hint: do it now.) Question 1 (10 points). (a) Define “local variable” and state when a local variable is created during a method call. (b) Below is a loop. Fill in the invariant, then the initialization, then the loop body // Store in c the number of positions i in Strings s1 and s2 such that s1[i] == s2[i] int n= Math.min(s1.length(), s2.length()); int c= ; // invariant: for ( int k= 0; k < n; k= k+1) { } // c = no. of positions i in s1[0. .n-1] and s2[0. .n-1] such that s1[i] == s2[i] 0 ___________ out of 02 1 ___________ out of 10 2 ___________ out of 15 3 ___________ out of 14 4 ___________ out of 22 5 ___________ out of 37 Total ________ out of 100
Background image of page 1

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

View Full DocumentRight Arrow Icon
Cornell net id ____________________ Name ________________________________ Section day ______________________ Section time ___________________________ Question 2 (15 points). At the bottom of the page are definitions of three classes: Student , Frosh , and Senior . Assume that these three statements have been executed: Student a= new Frosh("A", 3.1); Frosh c= new Frosh("C", 3.2); Senior d= new Senior("D", 3.3); Write the value of each expression given below; if one leads to an error, write "ERROR". It may help you to draw the objects that are created by execution of the three statements above. (2a) c.Bigger(a) (2f) d.getSound() (2b) a.getJob() (2g) ((Frosh)a).getSound() (2c) c.getJob() (2h) ((Frosh)d).getSound() (2d) d.getJob() (2i) ((Senior)d).getSound()
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

prelim2fall2006 - Cornell net id _ Section day _ Name _...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online