sp09M1 - CS 307 Midterm 1 Spring 2009 1 Points off 1 2 3 4...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: CS 307 Midterm 1 Spring 2009 1 Points off 1 2 3 4 Total off Net Score CS 307 Midterm 1 Spring 2009 Your Name____________________________________ Your UTEID __________________________________ Circle yours TAs name: Todd Guhan Xiuming(aka David) Instructions: 1. Please turn off or silence your cell phones. 2. There are 4 questions on this test. 3. You will 2 hours to complete the test. 4. You may not use a calculator or any other electronic devices while taking this test. 5. When code is required, write Java code. 6. When writing a method, assume the preconditions of the method are met. 7. When writing a method you may add helper methods if you wish. 8. When you complete the test show the proctor your UTID and give them the test and any scratch paper. Please leave the room quietly. 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 an exception answer "exception". If it would result in an infinite loop answer "infinite loop". A. What is the output of the following client code? public int methodA(int x, int y){ x++; y--; return x * y; } // client code int c = 4; int d = 5; System.out.println( methodA(c, d) + " " + d ); B. What is output by the following code? int listOne = {3, 2}; int listTwo = {2, 2}; listTwo[0]++; System.out.println( listOne == listTwo); CS 307 Midterm 1 Spring 2009 2 C. What is the output of the following client code? public void methodC(int list){ list[0]++; list = new int[3]; } // client code int data = {2, 1}; methodC(data); System.out.println( Arrays.toString(data) ); // prints out elements D. What is the output of the following client code? It uses method_c from part C. // client code int data2 = new int[0]; methodC(data2); System.out.println( Arrays.toString(data2) ); // prints out elements E. Consider the following method header: // pre: str != null public boolean allVowels(String str){ What were the two ways presented in class for checking the preconditions of methods such as str != null ? F. What is output by the following code? int x = 4; int y = 9; int table = new int[x * x][y / x]; System.out.println( table[3].length ); CS 307 Midterm 1 Spring 2009 3 For questions G O consider the following classes and interfaces. public interface Movable{ public int getMoveDistance(); } public class GroundUnit{ private String name; private int value; public GroundUnit(){ this("gen", 10); } public GroundUnit(String n, int v){ name = n; value = v; } public void upgrade(){ name = name + "I"; value += 10; } public String toString(){ return name + " " + value; } public int getNum(){ return value; } } public class Tank extends GroundUnit implements Movable{ private int moveValue; public Tank(String name, int value, int move){ super(name, value); moveValue = move; } public int getMoveDistance(){ return moveValue; } public void upgrade(){ super.upgrade(); moveValue += 2; } public int getNum(){ return moveValue; } }...
View Full 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 / 14

sp09M1 - CS 307 Midterm 1 Spring 2009 1 Points off 1 2 3 4...

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