fa08M1 - Points off 1 2 3 4 5 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
CS 307 – Midterm 1 – Fall 2008 1 Points off 1 2 3 4 5 Total off Net Score CS 307 – Midterm 1 – Fall 2008 Your Name____________________________________ Your UTEID __________________________________ Circle yours TA’s name: Mikie Sarah Ron Instructions: 1. Please turn off or silence your cell phones 2. There are 5 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 error answer "exception". If it would result in an infinite loop answer "infinite loop". A. What is the output of the following client code? // pre: list != null, list.length > 2 public void a(int[] list){ list[0] += list[1] + list[2]; list[1]++; list[2]--; } // client code int[] data = {3, 1, 5}; a(data); System.out.println( data[0] ); B. Would the following code, which calls method a from question A, result in a runtime error? Briefly explain your answer. int[] moreData = {0, 0}; a(moreData);
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS 307 – Midterm 1 – Fall 2008 2 Questions C through F make use of the following methods. public int b(int x){ x *= 2; return x; } public int b(int x, int y){ x--; y++; return x * y; } public int c(int x){ x /= 2; return x; } C. What is output by the following client code? int x = 3; b(x); System.out.println(x); D. What is output by the following client code? int y = 3; int z = c( b(y, y) ); System.out.println(z); E. What is output by the following client code? int m = 4; int n = 3; int p = b(m) + b(n, m); System.out.println(p); F. What is output by the following client code? int[] list = {4, 2, 6}; list[0] = b(list[1], list[2]); list[1] = c(list[1]); System.out.println( Arrays.toString(list) ); // prints out elements
Background image of page 2
3 For questions G – O consider the following classes and interfaces. public interface Taxable{ public int rate(); } public abstract class Item implements Taxable{ private String unit; public Item(String s){ unit = s; } public String baseUnit(){ return unit; } public abstract int basePrice(); public int cost(){ int tax = (int)(basePrice() * (rate() / 100.0)); return basePrice() + tax; } public String toString(){ return "item"; } } public class Shoes extends Item{ private int price; private int taxRate; public Shoes(int p, int r){ super("pair"); price = p; taxRate = r; } public int basePrice(){
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

fa08M1 - Points off 1 2 3 4 5 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