Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [24pts]

    Consider each expression below as appearing at the right here! in file Fruit.java, string that the resulting function call would produce.

    1. v1.foo()     ____________
    2. v1.foo('x')  ____________
    3. v1.foo(7)    ____________
    4. Jazz.bar(v1) ____________
    1. v2.foo()     ____________
    2. v2.foo('x')  ____________
    3. v2.foo(7)    ____________
    4. Jazz.bar(v2) ____________
    1. v3.foo()     ____________
    2. v3.foo('x')  ____________
    3. v3.foo(7)    ____________
    4. Jazz.bar(v3) ____________

  2. [76pts] Take a look at this program which is a tool for analyzing files. If you have a file foo, then cat foo | java HW11 will tell you whatever the program is able to determine about the type of the file foo. Your job is to extend it so that in addition to recognizing ASCII files and JPG files, it also recognizes PDF files (which begin with four bytes corresponding to the ASCII characters %, P, D, and F (i.e. bytes %PDF). You may not modify the files Categorizer.java, RecogASCII.java or RecogJPG.java, but you may modify HW11.java and you may create new classes. Remember that casting a char to an int is done like this:
    (int)'D'
    Test your program on the following:
    curl -s http://www.usna.edu/Users/cs/wcbrown/courses/S15IC211/lec/l11/hw/hwin1 | java HW11
    curl -s http://www.usna.edu/Users/cs/wcbrown/courses/S15IC211/lec/l11/hw/hwin2 | java HW11
    curl -s http://www.usna.edu/Users/cs/wcbrown/courses/S15IC211/lec/l11/hw/hwin3 | java HW11
    curl -s http://www.usna.edu/Users/cs/wcbrown/courses/S15IC211/lec/l11/hw/hwin4 | java HW11
Turn In: This sheet, of course, and a printout (using codeprint-java please!) of HW11.java and any new .java files you created, along with a screencapture showing your program's output on the above examples.