sp08M1 - 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 – Spring 2008 1 Points off 1 2 3 4 5 Total off Net Score CS 307 – Midterm 1[corrected] – Spring 2008 Your Name____________________________________ Your UTEID __________________________________ Circle yours TA’s name: Ruchica Mario Vishvas 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. Please make your answers legible. 6. When code is required, write Java code. 7. When writing a method, assume the preconditions of the method are met. 8. When writing a method you may add helper methods if you wish. 9. 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 code? int x = 2; int y = 7; int z = y / x + y * 2; System.out.println( z ); B. What is the output of the following code? double a = 5 / 2; double b = a; a++; System.out.println( b );
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 2008 2 C. Consider the following method. public int process(int[] data, int m1, int m2){ int t = 0; for(int i = 0; i < data.length; i++){ if( data[i] < m1 || data[i] > m2 ){ t++; } } return t; } What is printed out by the following code? int[] list = {5, 8, 13, 10, -5, 0, 9, 7, 12}; System.out.println( process(list, 3, 10) ); D. This question uses the method named process from part C. What is the output of the following code? int[] list2 = null; System.out.println( process(list2, 0, 12) ); E. Consider the following method. public void manip(int[][] mat){ for(int i = 0; i < mat[0].length; i++){ for(int j = i + 1; j < mat.length; j++){ mat[j][i] += mat[j - 1][i]; } } } Consider the following code. int[][] cells = {{1, 2, 3}, {-4, 5, 7}, {2, 5, 4}}; manip( cells ); What are the contents of the 2d array of ints named cells after the code above completes?
Background image of page 2
CS 307 – Midterm 1 – Spring 2008 3 For questions F – M consider the following classes. public class School{ private int numStudents; public School(int numStudents){ this.numStudents = numStudents; } public int getSize(){ return numStudents; } public String toString(){ return "Size: " + this.numStudents; } public void graduate(){ this.numStudents -= this.numStudents / 4; } } public class HighSchool extends School{ private String classification; public HighSchool(int numStudents, String classification){ super( numStudents ); assert validClassification( classification ); this.classification = classification; } public String toString(){ return "class: " + this.classification; } public static boolean validClassification(String s){
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 / 21

sp08M1 - 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