CS10, 09S, UCSB

H13: (Based on Horstman, Chapter 11, I/O and Exceptions) Total points: ? (printable PDF)

Accepted: on paper, in lecture (1-1:50pm) on Wednesday, May 13th only.
No email submission allowed.

Name: (2 pts)______________________________   UCSBNetID (2 pts)  _____________________

Section (6 pts) Circle one:         Thu 4pm                 Fri 10am                       Fri 11am                  Fri noon


  1. (10 pts) The standard way to write "Hello, World" to the screen is:

    System.out.println("Hello, World!"); 
    Let's take it to the next level. In the class below, after the Hello, World line, add three lines of code that will result in the message "Hello, Hard Drive!" being written into a file called "message.txt" in the current directory. Also note that you'll have to add something after the closing ) and before the opening { of the main method—I've left extra room for you to do that.

     /** 
    Standard example
    */
    public class HelloWorld
    {

    public static void main(String[] args)


    {
    System.out.println("Hello, World!");





    }
    }

    Please turn over for more problems

  2. (10 pts) Read Section 11.2 and then answer this question:

    Add some code to this constructor for a QuadraticEqn class so that you can be sure there will never be a QuadraticEqn object constructed where a is set to zero—instead, an appropriate exception should be thrown that indicates that the caller of the method made a bad choice for the argument of the function.

    public QuadraticEqn(double a, double b, double c)
    {



    this.a = a;
    this.b = b;
    this.c = c;
    }

  3. Read Sections 11.2, 11.3 and 11.4 before answering this question.

    Section 11.2 starts by saying that two main aspects of error handling are "reporting and recovery".

    1. (5 pts) What java keyword has to do error reporting, specifically?


    2. (5 pts) What pair of java keywords (used together) have to do with error recovery, specifically?



  4. (5 pts) What is the difference between a checked exception, and an unchecked exception?



  5. (5 pts) How do you define a new type of exception?








End of H13