final_10sp - CSE 142, Spring 2010 Final Exam Wednesday,...

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

View Full Document Right Arrow Icon
CSE 142, Spring 2010 Final Exam Wednesday, June 9, 2010 Name: ___________________________________________ Section: ___________________ TA: ___________________ Student ID #: ___________________ Rules: You have 110 minutes to complete this exam. You may receive a deduction if you keep working after the instructor calls for papers. This test is open-book/notes. You may not use any computing devices of any kind including calculators. Unless otherwise indicated, your code will be graded on proper behavior/output, not on style. You do not need to write any import statements in your code. Please do not abbreviate code, such as writing ditto marks ("") or dot-dot-dot marks (. ..). The only abbreviations allowed are S.o.p , S.o.pln , and S.o.pf for System.out.print , println , and printf . If you enter the room, you must turn in an exam and will not be permitted to leave without doing so. You must show your Student ID to a TA or instructor for your submitted exam to be accepted. Good luck! Problem Description Earned Max 1 Array Mystery 10 2 Reference Mystery 10 3 Inheritance Mystery 10 4 File Processing 15 5 Array Programming 15 6 Array Programming 15 7 Critters 15 8 Classes and Objects 10 X Extra Credit +1 TOTAL Total Points 100 1 of 11
Background image of page 1

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

View Full DocumentRight Arrow Icon
1. Array Mystery Consider the following method: public static void arrayMystery(int[] a) { for (int i = 1; i < a.length - 1; i++) { if (a[i] > a[i + 1]) { a[i] = a[i + 1] + a[i - 1]; } } } Indicate in the right-hand column what values would be stored in the array after the method arrayMystery executes if the array in the left-hand column is passed as its parameter. Original Contents of Array Final Contents of Array int[] a1 = {42, 99, 42}; arrayMystery(a1); int[] a2 = {6, 8, 4, 2}; arrayMystery(a2); int[] a3 = {7, 7, 20, 8, 1}; arrayMystery(a3); int[] a4 = {4, 5, 3, 2, 1, 0}; arrayMystery(a4); int[] a5 = {6, 0, -1, 80, 5, 0, -3}; arrayMystery(a5); _____________________________________ _____________________________________ _____________________________________ _____________________________________ _____________________________________ 2 of 11
Background image of page 2
2. Reference Semantics Mystery Write the output of the following program, as it would appear on the console. import java.util.*; // for Arrays class public class BasicPoint { int x; int y; public BasicPoint(int initialX, int initialY) { x = initialX; y = initialY; } } public class ReferenceMystery { public static void main(String[] args) { BasicPoint p = new BasicPoint(11, 22); int[] a = {33, 44}; int n = 55; System.out.println(p.x + "," + p.y + " " + Arrays.toString(a) + " " + n); mystery(p, a, n); System.out.println(p.x + "," + p.y + " " + Arrays.toString(a) + " " + n); a[0] = a[1]; p.x = p.y; mystery(p, a, n); System.out.println(p.x + "," + p.y + " " + Arrays.toString(a) + " " + n); } public static int mystery (BasicPoint p, int[] a, int n) { n = 0; a[0] = a[0] + 11; a[1] = 77; p.x = p.x + 33; System.out.println(p.x + "," + p.y + " " + Arrays.toString(a) + " " + n); return n; } } 3 of 11
Background image of page 3

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

View Full DocumentRight Arrow Icon
3. Inheritance Mystery
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

final_10sp - CSE 142, Spring 2010 Final Exam Wednesday,...

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

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