{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CSC108H-d06-part2

# CSC108H-d06-part2 - DECEMBER 2006 I FINAL EXAMINATION CSC...

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

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: DECEMBER 2006 I FINAL EXAMINATION CSC 108H /** Remove the book with title t and author a from the library. * This can only be done if the book is in the library’s catalogue * and it is not currently loaned. Return true if the book is removed, * and false otherwise. */ public boolean removeBook( String t, String a ) { /** Transfer book b to library 1. Book b can only be transferred from * this library if b is in this library’s catalogue and it is not currently * loaned, and if there is enough room in library 1. Return true if the book * is transferred, and false otherwise. You may assume that b is not * already in l. */ public boolean transfer(LibraryBook b, Library 1) { Student#:. . . I , . . . . , Page 11 0f18 CONT’D... CSC 108H FINAL EXAMINATION DECEMBER 2006 Question 8. [20 MARKS] Part (a) [6 MARKS] Both the linear and binary search algorithms we saw in class assumed that the array is in sOrted order. Complete the following method: /** Return true if list is sorted alphabetically, and false otherwise. */ public static boolean inOrder(String list) { } Part (b) [14 MARKS] Write a public static method called paritySort that takes an int and partially sorts its elements: the elements with even indices are sorted relative to each other and the elements with odd indices are sorted relative to each other. For instance, if the original list is: The ints in the array may occur more than once. You will be marked on design, correctness, and efﬁciency. You may add helper methods. Student #:. , , . . . , , , , Page 120f18 CONT’D... DECEMBER 2006 FINAL EXAMINATION CSC 108H Write your answer to Question 8. (b) here. Student #:. , . . . l , , . , Page 130f18 CONT’D... CSC 108H FINAL EXAMINATION DECEMBER 2006 [Use the space below for rough work. This page will not be marked, unless you clearly indicate the part of your work that you want us to mark. ] Student #2. . , I , . ‘ , . . Page 14of18 CONT’D... DECEMBER 2006 FINAL EXAMINATION CSC 108H [Use the space below for rough work. This page will not be marked, unless you clearly indicate the part of your work that; you want us to mark] Student#:, , . , I , . , . . Page 15of18 CONT’D... CSC 108H FINAL EXAMINATION DECEMBER 2006 [Use the space below for rough work. This page will not be marked, unless you clearly indicate the part of your work that you want us to mark. ] Student#:. , , , , I . . , , Page 160f18 CONT’D... DECEMBER 2006 FINAL EXAMINATION CSC 108H Short Java API descriptions (everything is public) Object: boolean equals(0bject o) // = "this Object is equal to 0" String toString() // = a String representation of this Object Integer: static int parseInt(String s) // = s’s value, as an int Double: static double parseDouble(String s) // = s’s value, as a double Boolean: static boolean parseBoolean(String s) // = s’s value, as a boolean String: String substring(int i, int j) // = the letters from i (inclusive) to j (non-inclusive) String substring(int i) // = the letters from i (inclusive) to the end int index0f(String s) // = the index of s in this String; -1 if s is not a substring int indefo(String 8, int i) // = index of s after index i (inclusive); -1 if s not found int compareTo(String s) // < 0, = 0, or > 0 depending on whether this < s, = s, or > s. int 1ength() // = the number of characters in this String boolean equals(String s) // = this String has the same contents as s ‘StringTokenizer: StringTokenizer(String s) // Create a tokenizer for s with delimiters " \t\n\r\f" StringTokenizer(String 3, String d) // Create a tokenizer for s with delimiters in d boolean hasMoreTokens() // = whether this string tokenizer has more tokens String nextToken() // = the next token in this tokenizer’s string int countTokens() // = the number of remaining tokens in this tokenizer’s string File: File(String pathname) // Create a File linked with a file named f BufferedReader: BufferedReader(Reader in) // Create a reader reading from ’in’ // Return the next available line in the BufferedReader, or null if at end String readLine() FileReader: FileReader(String f) // Create a Reader reading from a file named f FileReader(File f) // Create a Reader reading from a file f InputStreamReader: InputStreamReader(InputStream in) // Create a Reader reading from in FileDutputStream: FileUutputStream(File f) // Create an OutputStream writing to f FileOutputStream(String f) // Create an OutputStream writing to a file named f PrintStream: PrintStream(0utputStream out) // Create a print stream sending output to out print(String s) // Print 3 to the output print(int i) // Print 1 to the output (similar methods exist for all primitive types) println(String s) // Print s to the output println(int i) // Print i to the output and terminate the line // (similar methods exist for all primitive types) println() // terminate the lines Student #:I I I I I I I I I I Page 17of18 CONT’D... CSC 108H FINAL EXAMINATION DECEMBER 2006 System: static InputStream in // input from the keyboard static PrintStream out // standard output stream Math : static double abs(double a) // = the absolute value of a static double pow(doub1e a, double b) // = a‘b static double min(double a, double b) // = minimum of a and b static double max(doub1e a, double b) // = maximum of a and b Container: // add item c in location specified by loc, which is "North", "South", "East", "West", or // "Center". For example, add(new JButton("A"), "East") adds a new JButton in the east add(Component c, String loc) add(Component c) // add c to the next spot in the container void setLayout(LayoutManager 1m) // set this JFrame’s layout manager to 1m JFrame: JFrame() // An empty window with no title, not visible on the screen JFrame(String s) // An empty window with title s, not visible on the screen Container getContentPane() // this JFrame’s content pane int getWidth() // this JFrame’s width int getHeight() // this JFrame’s height int getX() // this JFrame’s horizontal coordinate int getY() // this JFrame’s vertical coordinate void setSize(int w, int h) // set this JFrame’s size to w wide and h high void setTitle(String s) // set this JFrame’s title to s void setLocation(int x, int y) // set this JFrame’s location to (x, y) void setVisible(boolean b) // make this JFrame visible/invisible J0ptionPane: static String showInputDialog(String m) // get input from the user, prompting with m static void showMessageDialog(Component 0, Object message) // alert the user, with m JTextArea: JTextArea(int r, int c) // text area with r rows and c columns, and no initial text JTextArea(String s, int r, int c) // text area with r rows, c columns, and initial text s void setText(String s) // set the text in this text area to s void append(String s) // append s to the text in this text area String getText() // = the text in this text area JButton: JButton() // A button with no name JButton(String s) // A button named 5 String getText() // = this JButton’s name JLabel: JLabe1() // A label with no text JLabelCString s) // A label containing text s String getText() // = this JLabel’s text String setText(String s) // = set this JLabel’s text to s Student #:. , I . I . , . I . Page 18 of 18 END OF EXAMINATION ...
View Full Document

{[ snackBarMessage ]}

### Page1 / 8

CSC108H-d06-part2 - DECEMBER 2006 I FINAL EXAMINATION CSC...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online