fa04m1 - Points off 1 2 3 4 Admin Total off Net Score CS...

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

View Full Document Right Arrow Icon
Points off 1 2 3 4 Admin Total off Net Score CS 307 – Midterm 1 – Fall 2004 Your Name____________________________________ Your UTEID __________________________________ Your TAs name ________________________________ (Alison, Allen, or Peter) Instructions: 1. There are 4 questions on this test. 2. You will have 2 hours to complete the test. 3. You may not use a calculator. 4. Please make your answers legible. 5. When code is required, write Java code. 6. The class style guide and coding standards are not in effect 7. You are not graded on the efficiency of your solutions unless stated. 8. You may not use any classes' or methods from the Java Standard Library except as noted. You may use System.out.println, System.out.print, any classes' equals method, and native arrays. 1. (2 points each, 30 points total) Short answer questions. For code sample state the output. If the code would cause a syntax error answer "syntax error" and if it would cause a runtime error answer "runtime error". A. What is the output of the following code? int x = 17; int y = x / 4; y++; int z = x - y; System.out.println( z ); _______________________________________________ CS 307 – Midterm 1 – Fall 2004 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
B. What is the output of the following code? public void creed(int x, int y) { x = x – 2; y = x * 2; System.out.print(" " + x + " " + y); } int a = 4; int b = 3; creed(a, b); System.out.print(" " + a + " " + b); _______________________________________________ C. What is the output of the following code? int y = 4; int[] list = new int[ y * 2 ]; for(int i = 0; i < list.length; i++) list[i] = i / 2; System.out.println( list[ list[4] ] ); _______________________________________________ D. What is the output of the following code? double[][] mat = new double[3][4]; for(int i = 0; i < mat.length; i++) for(int j = 0; j < 4; j++) mat[i][j] = i * j / 2.0; for(int i = 0; i < 4; i++) System.out.print( " " + mat[1][i] ); _______________________________________________ CS 307 – Midterm 1 – Fall 2004 2
Background image of page 2
E. What is the output of the following code? String s1 = "total"; int x = 5; int y = 4; s1 = s1 + x + y; System.out.println(s1); _______________________________________________ For questions F through M consider the following two classes. public class Vessel { private int iMyWeight; public Vessel() { iMyWeight = 1000; } public Vessel(int weight) { iMyWeight = weight; } public void alterWeight(int weight) { iMyWeight = weight; } public String toString() { return "vessel weight: " + iMyWeight; } } public class Sailboat extends Vessel
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 / 16

fa04m1 - Points off 1 2 3 4 Admin Total off Net Score CS...

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