fa05m - Points off 1 2 3 4 Total off Net Score CS 307...

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 Total off Net Score CS 307 – Midterm 1 – Fall 2005 Your Name____________________________________ Your UTEID __________________________________ TA’s Name ___________________________________ (Peggy, Don, or Chendi) Instructions: 1. There are 4 questions on this test. 2. You will 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. When completing a method, assume the preconditions of the method are met. 7. You are not graded on the efficiency of your solutions unless stated. 1. (2 points each, 30 points total) Short answer questions. Place your answers on the attached answer sheet. For code sample state the output. If the code would cause a syntax error answer "syntax error". If it would cause a runtime error answer "runtime error". If it would result in an infinite loop answer "infinite loop". Place you answers on the attached answer sheet. A. What is the output of the following code? int a = 3; int b = 17 – a * a; a++; System.out.println( a + " " + b ); B. What is the output of the following code? int x = 0; final int LIMIT = 5; for(int i = 0; i < LIMIT; i++) x += (i + LIMIT); System.out.println( x ); CS 307 – Midterm 1 – Fall 2005 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. What is the output of the following code? String[] list = {"Hi", "Cup", "Spoon", "Plate", "Knife", "Bowl"}; int index = 2; System.out.println( list[index * index] ); D. What is the output of the following code when method blue is called? public int red(int x, int y) { return x * y; } public int purple(int z) { int temp1 = red(z, z + 2); int temp2 = red(z, z – 2); return temp1 + temp2; } public void blue() { int t1 = red(2, 3); int t2 = purple(3); int result = t1 + t2; System.out.println( result ); } E. What is the output of the following code when method violet is called? public void periwinkle(int x, int y) { x += 2; y -= 3; System.out.println( x + " " + y ); } public void violet() { int x = 3; int y = 4; System.out.println( x + " " + y ); periwinkle(x, y); System.out.println( x + " " + y ); } CS 307 – Midterm 1 – Fall 2005 2
Background image of page 2
For questions F through O consider the following two classes. public abstract class ThreeDShape { private String myColor; public ThreeDShape() { myColor = “pink”; } //pre: color != null public ThreeDShape(String color) { myColor = color; } public abstract int getVolume(); public String toString() { return “color: “ + myColor;} } public class Cube extends ThreeDShape { private int myLength; public Cube() { myLength = 1; } //pre: length > 0 public Cube(int length) { myLength = length; } //pre: color != null, length > 0 public Cube(String color, int length) { super(color); myLength = length; } public int getVolume() { return myLength * myLength * myLength; } public void doubleLength()
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.

This note was uploaded on 11/30/2010 for the course CS 307 taught by Professor Scott during the Spring '08 term at University of Texas at Austin.

Page1 / 20

fa05m - Points off 1 2 3 4 Total off Net Score CS 307...

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