midterm1Spring02 - Points off 1 2 3 4 Admin Total off Net...

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 Admin Total off Net Score CS 307 – Midterm 1 – Spring 2002 Name____________________________________ Last 4 digits of SSN / Student ID ______________ Class Unique ID ___________________________ 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. When code is required, write Java code. 5. Please make your answers legible. 6. The style guide is not in effect except as noted. 1. (2 points each, 30 points total) Java Mechanics. For all parts, what is the output of the code fragment? Write your answer on the line provided. Consider each piece of code in isolation. If an error would occur answer "syntax error" or "runtime error" depending on what type of error it would be. A. _________________________________________________ int limit = 20; int[] intList = new int [limit / 3]; for (int i = 0; i < intList.length; i++) { if (i % 3 == 0) intList[i] = i; else intList[i] = -1; } for (int i = 0; i < intList.length; i++) System.out.println( intList[i] ); 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
B. _________________________________________________ int x = 34; int y = 45; int z = 123; double answer; answer = ( x / y ) * (double)( y / z ); System.out.println( answer ); C. _________________________________________________ int i = 0; int j = 4 / i; System.out.println( "j = " + j ); D. _________________________________________________ double a = 0.0; double b = 2.5; int x = 13; int y = 28; a = b + y % x; System.out.println( a ); E. _________________________________________________ // The BigInteger class is part of the java.lang // package. It is a class that can be used to // represent arbitrary precision integers, // integer much larger than int or long can // represent. Passing a String to the BigInteger // constructor creates a new BigInteger object // representing the argument BigInteger b1 = new BigInteger("1212"); BigInteger b2 = new BigInteger("1212"); System.out.println( b1 == b2 ); CS 307 – Midterm 1 – Fall 2001 2
Background image of page 2
F. _________________________________________________ // two BigInteger Objects are "equal" if the // integer values they are representing are equal. BigInteger b1 = new BigInteger("1212"); BigInteger b2 = new BigInteger("1212"); System.out.println( b1.equals(b2) ); G. _________________________________________________ Assume the following two methods appear in the same class, Foo. public int chalk( int m, int p ) { int t = m; m = m + 2 * p; return t + m + p; } public void marker( int x, int y ) { x = x + 2; y++; System.out.println( chalk(x, y) + " " + x + " " + y ); } What is the output of the following method call? someFooObject.marker(2, 4); 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
For parts H and I consider these three classes: public abstract class Mammal { public String birthType() { return "Live Birth."; } //other methods and instance vars not shown } public class Platypus extends Mammal { public String birthType() { return "Lays eggs."; } //other methods and instance vars not shown
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.

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 / 13

midterm1Spring02 - Points off 1 2 3 4 Admin Total off Net...

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