Quiz 9

Friday

With a piece of paper, write down your name and answers to the following questions.

  1. What is an interface?

    1. An interface is a collection of public methods.
    2. An interface is a collection of interactive graphic components.
    3. An interface is a collection of method definitions and constants.
    4. An interface is a class that serves as the superclass of other classes.
  2. What will the following program print?

    import java.util.StringTokenizer;
    
    public class Program {
    	public static void main(String[] args) {
    		String str = "one#two@three";
    		StringTokenizer strTokenizer = new StringTokenizer(str, "&%@#", true);
    		while (strTokenizer.hasMoreTokens())
    			System.out.println(strTokenizer.nextToken());
    	}
    }

    Answer:
        one
        #
        two
        @
        three

  3. Is the following statement correct, and why?

    Every class has a toString method and an equals method inherited from the Object class.

    Answer: Yes, this statement is correct.

  4. With the following class hierarchy...

    Exception Inheritance Tree

    Is the following code correct, and why?

    public class Program {
    	public static void main(String[] args) {
    		try {
    			Scanner scanner = new Scanner(System.in);
    			int num = scanner.nextInt();
    
    		} catch (NoSuchElementException e) {
    			System.err.println("No Such Element");
    
    		} catch (InputMismatchException e) {
    			System.err.println("Input Mismatch");
    		}
    	}
    }

    Correction:

    public class Program {
    	public static void main(String[] args) {
    		try {
    			Scanner scanner = new Scanner(System.in);
    			int num = scanner.nextInt();
    
    		} catch (InputMismatchException e) {
    			System.err.println("Input Mismatch");
    
    		} catch (NoSuchElementException e) {
    			System.err.println("No Such Element");
    		}
    	}
    }

Student Performance and Statistics

A histogram of student performance on percentage grades for Quiz 9 on Friday.

100% 1 90 - 99% 0 80 - 89% 0 70 - 79% 2 60 - 69% 0 50 - 59% 1 40 - 49% 0 30 - 39% 2 20 - 29% 2 10 - 19% 0 0 - 9% 0

A table showing the average performance for each question in Quiz 9 on Friday.

Q1 0.4 / 1 Q2 0.8 / 1 Q3 0.6 / 1 Q4 0.2 / 1