2009Spring_final - - 1 - 1 (30 points) 2 (20 points) 3 (25...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: - 1 - 1 (30 points) 2 (20 points) 3 (25 points) 4 (25 points) TOTAL (100 points) 19.94 12.18 12.95 8.70 53.78 CS101 Introduction to Programming 2009 Spring Final Examination SECTION STUDENT ID NAME TA CONFIRM ※ Fill out the above information CORRECTLY or you will get some penalties. 1 Answer each question according to the instruction. 1-1 Choose an incorrect description. ( ⑤ ) (3 points) ① All exception classes are derived from the predefined class Exception. ② If an exception occurs within a try block, the rest of the block is ignored. ③ Though the keyboard input and screen output deal with temporary data, files provide you with a way to store data permanently. ④ In inheritance, derived class inherits the public instance variables and public methods of the base class that it extends. ⑤ In generics, you can use a primitive type for a type parameter. For example, the following statement is correct. ArrayList<int> aList = new ArrayList<int>(20);- 2 - throws Exception ① seat(0,1) is reserved by Jessica seat(1,1) is reserved by Tiffany The seat (1,1) is unavailable. ② The seat (1,1) is unavailable. seat(0,1) is reserved by Jessica seat(1,1) is reserved by Tiffany ③ seat(0,1) is reserved by Jessica seat(1,1) is reserved by Tiffany ④ seat(0,1) is reserved by Jessica ⑤ seat(1,1) is reserved by Tiffany ※ This program is for seat reservation. Answer the following questions. (1-2 and 1-3) public class SeatReservation { public static void reservation(int row, int col, String name, String seat) (a) { if( (row >= 0 && row < seat.length && col >= 0 && col < seat[row].length) && (seat[row][col]==null) ) { seat[row][col] = name; System.out.println("seat"+"("+row+","+col+") is reserved by "+name); } else { throw new Exception("The seat ("+row+","+col+") is unavailable."); } } public static void main(String args) { String seat = new String[3][3]; try{ reservation(0, 1, "Jessica", seat); reservation(1, 1, "Tiffany", seat); reservation(1, 1, "Yoon Ah", seat); } catch(Exception e){ System.out.println(e.getMessage()); } } } 1-2 Fill in the blank (a) with proper expression. (3 points) 1-3 Choose a correct execution result for this program. ( ① ) (3 points)- 3 - 1-4 Given the following class Point and PointTest, what output is produced by the following program? ( ② ) (3 points) public class Point { private int x, y; public Point(int x, int y) { this.x = x; this.y = y; } public String toString() { return "(" + x + ", " + y + ")"; } } public class PointTest { public static void main(String args) { Point arr = { new Point(3, 4), new Point(7, 2) }; int index1 = 0, index2 = 1; swap(arr, 0, 1); swap(index1, index2); System.out.println(arr[index1]); System.out.println(arr[index2]); } public static void swap(int a, int b) { int temp = a; a = b; b = temp; } public static void swap(Point arr, int index1, int index2) { Point temp = arr[index1]; arr[index1] = arr[index2]; arr[index2] = temp; } } ① (3, 4) (7, 2) ② (7, 2) (3, 4) ③ (7, 2) (7, 2) ④ (3, 4) (3, 4) ⑤ (0, 1) (1, 0) ⑥ (1, 0) (0, 1)- 4 -...
View Full Document

Page1 / 17

2009Spring_final - - 1 - 1 (30 points) 2 (20 points) 3 (25...

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