{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

sp08M1 - Points off 1 2 3 4 5 Total off Net Score CS 307...

Info icon This preview shows pages 1–5. 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 );
Image of page 1

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

View Full Document Right 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?
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){ boolean result = s != null && s.length() >= 0 && s.length() <= 5; if( result ) result = s.equals("A") || s.equals("AA") || s.equals("AAA") || s.equals("AAAA") || s.equals("AAAAA"); return result; } } public class University extends School{ private String name; public University(int numStudents, String name){ super(numStudents); this.name = name; } public String toString() { return this.name + ", " + super.toString(); } }
Image of page 3

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

View Full Document Right Arrow Icon
CS 307 – Midterm 1 – Spring 2008 4 F.
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern