sp10M1 - Points off 1 2 3A 3B 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
CS 307 – Midterm 1 – Spring 2010 1 Points off 1 2 3A 3B 4 Total off Net Score CS 307 – Midterm 1 – Spring 2010 Your Name____________________________________ Your UTEID __________________________________ Circle yours TA’s name: Guillermo Reza Shyamala Instructions: 1. There are 4 questions on this test. 2. You have 2 hours to complete the test. 3. You may not use a calculator or any other electronic devices while taking the test. 4. When writing a method assume the preconditions of the method are met. 5. When writing a method you may add helper methods if you wish. 6. 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 a runtime exception answer "exception". If it would result in an infinite loop answer "infinite loop". Questions A and B use the following method. public void helper(int[] vals){ vals[vals.length - 1] += 3; vals = new int[2]; vals[0]++; } A. What is output by the following code when method a is called? public void a(){ int[] data = {2, 3}; helper(data); System.out.println(Arrays.toString(data)); } B. What is output by the following code when method b is called? public void b(){ int[] data = new int[0]; helper(data); System.out.println(Arrays.toString(data)); }
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 – Spring 2010 2 For questions C – M consider the following classes and interfaces. Recall, the Comparable interface has one method, compareTo which returns an int . public abstract class Property implements Comparable{ private String name; public abstract int getValue(); public Property(String str){ name = str; } public String toString(){ return name; } public int compareTo(Object other){ return getValue() - ((Property)other).getValue(); } } public class Business extends Property{ private int area; public Business(String str, int a){ super(str); area = a; } public int getValue(){ return area * 100; } } public class Residential extends Property { private int rooms; public Residential(int r){ super("Res"); rooms = r; } public int getValue(){ return rooms * 1000; } public void addOn(){ rooms++; } } public class Rented extends Residential { public Rented(int r){ super(r); } public int getValue(){ return super.getValue() / 2; } } public class Owned extends Residential { private int yardArea; public Owned(int y){ this(y, 4); } public Owned(int y, int r){ super(r); yardArea = y; } public String toString(){ return "" + yardArea; } }
Background image of page 2
CS 307 – Midterm 1 – Spring 2010 3 C. State if the following declarations are valid or invalid (meaning they cause a syntax error). 1 point each
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.

Page1 / 15

sp10M1 - Points off 1 2 3A 3B 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