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

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 2003 Your Name____________________________________ Your UTEID __________________________________ Your USL's Name________________________________ 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. 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 methods, and native arrays. 1. (3 points each, 30 points total) Short answer questions. For code sample state the output. If the output would cause a syntax error answer "syntax error" and if it would cause a runtime error answer "runtime error" In the case of an error explain what caused the syntax error or runtime error. A. What is the output of the following code? int[] list = {16, 9, 4, 1}; int[] otherList = new int[list[1]]; for(int i = 0; i < otherList.length; i++) otherList[i] = list[3] + i * i; System.out.println( otherList[0] + " " + otherList[5] + " " + otherList[otherList.length-1]); ____________________________________________ CS 307 – Midterm 1 – Fall 2003 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? int[][] mat = new int[5][4]; for(int c = 2; c < mat[0].length; c++) for(int r = 1; r < 4; r++) mat[r][c] = r * c; int total = 0; for(int c = 0; c < mat.length; c++) total += mat[c][c]; System.out.println( total ); _________________________________________________ C. Consider the following method: public static void hershey(int a, int b) { int x = a * 2; int y = b * 3; System.out.println(a + " " + b + " " + x + " " + y); b--; a++; System.out.println(a + " " + b + " " + x + " " + y); } What is the output of the following code? int x = 5; int y = 3; System.out.println( x + " " + y ); hershey(x, y); System.out.println( x + " " + y ); _________________________________________________ CS 307 – Midterm 1 – Fall 2003 2
Background image of page 2
For questions D – J Consider the following classes: public abstract class Candy { private String myName; private int iMyCalories; public Candy() { myName = "unknown"; iMyCalories = 0; } public Candy(String name) { myName = name; iMyCalories = 0; } public Candy(String name, int calories) { myName = name; iMyCalories = calories; } public String toString() { return myName + " " + iMyCalories; } public void setCalories(int calories) { iMyCalories = calories; } public int getCalories() { return iMyCalories ; } public abstract String getDescriptor(); } public class ChocolatyCandy extends Candy { private String myAdj;
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 / 12

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

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