{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CSE 17 Test 2 FALL 2006

CSE 17 Test 2 FALL 2006 - CSE 17 Test 1 Friday 17 November...

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

View Full Document Right Arrow Icon
CSE 17 Test 1 Friday 17 November 2006 <<<<<<<<<<<<<<<<<<<<<<SUGGESTED ANSWERS>>>>>>>>>>>>>>> 1. Assume the following class: public class Node{ public int j; public Node next; } Write a method list() for listing the contents of a linked list of Nodes in the file "test2.out". Given Node hd;, where hd points to a linked list that terminates in a null pointer, the call list(hd,"test2.out") should list the contents of the linked list in the file "test2.out". <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< public static void list(Node hd,String file){ try{ PrintWriter out=new PrintWriter(new FileOutputStream(file)); while(hd!=null){ out.println(hd.j); hd=hd.next; } out.close(); }catch(FileNotFoundException e){ System.err.println("The file 'afile.out' could not be opened"); System.exit(1); } } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2. Write an abstract class Bound, that requires its subclasses to have functions max() and min() that are meant to return the largest (max()) and smallest (min()) ints among the data stored by the given subclass. The class Bound should also have a function, inRange(), that returns true if and only if a given int is between the smallest and largest int (inclusive) among the ints stored by the subclass. A sample
Background image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}