final_09au - CSE 142, Autumn 2009 Final Exam Wednesday,...

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

View Full Document Right Arrow Icon
1 of 11 CSE 142, Autumn 2009 Final Exam Wednesday, December 16, 2009 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 File Processing 10 6 Array Programming 15 7 Array Programming 10 8 Critters 10 9 Classes and Objects 10 X Extra Credit +1 TOTAL Total Points 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
2 of 11 1. Array Mystery Consider the following method: public static void arrayMystery(int[] a) { for (int i = 1; i < a.length - 1; i++) { a[i] = a[i - 1] - a[i] + 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, 42}; arrayMystery(a1); int[] a2 = {6, 2, 4}; arrayMystery(a2); int[] a3 = {7, 7, 3, 8, 2}; arrayMystery(a3); int[] a4 = {4, 2, 3, 1, 2, 5}; arrayMystery(a4); int[] a5 = {6, 0, -1, 3, 5, 0, -3}; arrayMystery(a5); _____________________________________ _____________________________________ _____________________________________ _____________________________________ _____________________________________
Background image of page 2
2. Reference Semantics Mystery The following program produces 4 lines of output. Write the output below, as it would appear on the console. import java.util.*; // for Arrays class public class BasicPoint { int x; int y; public BasicPoint(int x, int y) { this.x = x; this.y = y; } } public class ReferenceMystery { public static void main(String[] args) { int n = 10; int[] a = {20}; // an array with just one element BasicPoint p = new BasicPoint(30, 40); mystery(n, a, p); System.out.println(n + " " + Arrays.toString(a) + " " + p.x + "," + p.y); a[0]++; p.x++; mystery(n, a, p); System.out.println(n + " " + Arrays.toString(a) + " " + p.x + "," + p.y); } public static int mystery(int n, int[] a, BasicPoint p) { n++; a[0]++; p.y++; System.out.println(n + " " + Arrays.toString(a) + " " + p.x + "," + p.y); return n; } }
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

final_09au - CSE 142, Autumn 2009 Final Exam Wednesday,...

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

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