Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. Consider the program HW1 below, which makes use of the method
    public static double compute(Scanner sc) throws Exception
    of the class Mystery. You can get Mystery.class with:

    Here are some sample runs:
    ~/$ java HW1
    23 12 17
    8 -12
    2 5 8
    57.637144696875005
    ~/$ java HW1
    23 12
    17 the 8
    
    Error bad input string "the"
    ~/$ java HW1
    12
    0
    18 13
    34.2 89
    Error bad input string "34.2"
    Your job is to modify the class HW1 so that
    1. when an error message is printed, the input line number that caused the error is printed out (look at the LineNumberReader class from the Java API), and
    2. if there are command-line arguments, input will be read from a file (instead of standard in) whose name is the first command-line argument. The program will behave just as before (including the line number in the error message), except the input comes from a file.
    ~/$ java HW1
    23 12 17
    8 -12
    2 5 8 ← ctrl-d to signal end of input 
    57.637144696875005
    ~/$ java HW1
    23 12
    17 the 8
    Error bad input string "the" at line 2 
    ~/$ java HW1 ina.txt 
    57.637144696875005
    ~/$ java HW1 xyz.txt
    File "xyz.txt" not found 
    ~/$ java HW1 inb.txt
    Error bad input string "the" at line 2 
submit
submit -c=IC211 -p=hw17 HW1.java