{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

This preview shows pages 1–5. Sign up to view the full content.

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

View Full Document
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?
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(); } }

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

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

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern