midterm1Fall2001verFinal

midterm1Fall2001verFinal - Points off 1 2 3 4 5 Admin Total...

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

View Full Document Right Arrow Icon
Points off 1 2 3 4 5 Admin Total off Net Score CS 307 – Midterm 1 – Fall 2001 Name____________________________________ Last 4 digits of SSN / Student ID ______________ Class Unique ID ___________________________ Instructions: 1. There are 5 questions on this test. 2. You will have 2 hours to complete the test. 3. You may not use a calculator. 4. When code is required, write Java code. 5. The style guide is not in effect. 6. Please try to make your answers are legible. 7. Efficiency will not be graded except for question 5. 1. (2 points each, 20 points total) Java Mechanics and algorithmic analysis. For parts A – G what is the output of the code fragment? Consider each piece of code in isolation. Put your answer directly after each fragment. If an error would occur answer "syntax error" or "runtime error" depending on what type of error it would be. A. int x = 5; int y = 11; double a = x * y; double b = 1.5; b = a / x + b + y + y / x; System.out.println(b); B. Color c1 = new Color(100, 25, 200, 100); // previous line of code creates a new Color object. Color c2; c2 = c1; System.out.println(c2 == c1); c2 = new Color(100, 25, 200, 100); System.out.println(c1 == c2); CS 307 – Midterm 1 – Fall 2001 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
C. int t = 2; int s = 37; int j = 33; for(int i = 1; i < s; i += 5) t += j % i; System.out.println(t); D. int x = 27; int y = 14; int[] intList = new int[ y % x - 3]; for(int i = 0; i < intList.length; i++) { if(i % 2 == 0) intList[i] = i * i; else intList[i] = i + i + 1; } int t = 0; for(int i = 0; i < intList.length; i++) System.out.print(intList[i] + " "); E. For part E methods one and two are in the same class. Assume method two has just been called with the following parameters: someObject.two(7, 12); public int one(int a, int b) { int temp = a; a = b; b = temp; System.out.println(a + " " + b); return a + b; } public void two(int a, int b) { int x = 5; a = x * 2; b += 3; System.out.println( one(b,a) + " " + a + " " + b); } CS 307 – Midterm 1 – Fall 2001 2
Background image of page 2
F. For part F consider the following class: public class Bad { public int one; public int two; } The following two methods both appear in another class. Assume the following method call has just been made: someObject.go(); public void helper(Bad b) { int temp = b.one; b.one = b.two; b.two = temp; System.out.println(b.one + " " + b.two); } public void go() { Bad bb = new Bad(); bb.one = 20; bb.two = 5; System.out.println(bb.one + " " + bb.two); helper(bb); System.out.println(bb.one + " " + bb.two); } CS 307 – Midterm 1 – Fall 2001 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
G. Part G uses the same class, Bad, from part F. The following two methods both appear in
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 / 10

midterm1Fall2001verFinal - Points off 1 2 3 4 5 Admin Total...

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