c17f06t2 - CSE 17 Test 1 Friday 17 November 2006

Info icon This 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
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
Image of page 2
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