Quiz 6

Wednesday

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

  1. What is the name of the character that separates tokens in a string?

    1. Separator
    2. Tokenizer
    3. Delimiter
    4. Terminator
  2. The startsWith and endsWith methods are members of which class?

    1. Char
    2. Character
    3. StringBuilder
    4. String
  3. Which StringTokenizer method returns true if there are more tokens to be extracted from a string?

    1. moreTokens
    2. tokensLeft
    3. getToken
    4. hasMoreTokens
  4. Is the following statement correct, and why?

    Character testing methods in the Character class, such as isLetter, accept strings as arguments and test each character in the string.

    Answer: False, character testing methods in the Character class, such as isLetter, accept char type data as arguments

  5. Find and correct the error in the following program.

    public class Program {
    	public static void main(final String[] args) {
    		StringBuilder builder = "CSCI 2912";
    		builder.append("Hawaii Pacific University");
    	}
    }

    Correction:

    public class Program {
    	public static void main(final String[] args) {
    		StringBuilder builder = new StringBuilder("CSCI 2912");
    		builder.append("Hawaii Pacific University");
    	}
    }

    Or:

    public class Program {
    	public static void main(final String[] args) {
    		StringBuilder builder = new StringBuilder();
    		builder.append("CSCI 2912");
    		builder.append("Hawaii Pacific University");
    	}
    }

Student Performance and Statistics

A histogram of student performance on percentage grades for Quiz 6 on Wednesday.

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

A table showing the average performance for each question in Quiz 6 on Wednesday.

Q1 0.7 / 1 Q2 0.6 / 1 Q3 0.9 / 1 Q4 0.8 / 1 Q5 0.8 / 1

Friday

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

  1. What is one of the methods that are common to both the String and the StringBuilder classes?

    1. length
    2. insert
    3. append
    4. delete
  2. The isLetter, isDigit, and isUpperCase methods are members of which class?

    1. Char
    2. Character
    3. StringBuilder
    4. String
  3. These static final variables are members of the numeric wrapper classes, and they hold the minimum and maximum values for a particular data type. What are they?

    1. MIN_VALUE and MAX_VALUE
    2. MIN and MAX
    3. MINIMUM and MAXIMUM
    4. LOWEST and HIGHEST
  4. Is the following statement correct, and why?

    To use a numeric wrapper class, such as Character, you need to write the corresponding import statement.

    Answer: False, first, the Character wrapper class is not numeric; second, wrapper classes are part of the java.lang package, so there is no need for an import statement.

  5. Find and correct the error in the following program.

    import java.util.StringTokenizer;
    
    public class Program {
    	public static void main(final String[] args) {
    
    		// Tokenize a string that is delimited with semicolons.  This
    		// string contains three tokens: "one", "two", and "three".
    		StringTokenizer tokenizer = new StringTokenizer("one;two;three");
    
    		while (tokenizer.hasMoreTokens())
    			System.out.println(tokenizer.nextToken());
    	}
    }

    Correction:

    import java.util.StringTokenizer;
    
    public class Program {
    	public static void main(final String[] args) {
    
    		// Tokenize a string that is delimited with semicolons.  This
    		// string contains three tokens: "one", "two", and "three".
    		StringTokenizer tokenizer = new StringTokenizer("one;two;three", ";");
    
    		while (tokenizer.hasMoreTokens())
    			System.out.println(tokenizer.nextToken());
    	}
    }

    Or:

    import java.util.StringTokenizer;
    
    public class Program {
    	public static void main(final String[] args) {
    
    		// Tokenize a string that is delimited with spaces.  This
    		// string contains three tokens: "one", "two", and "three".
    		StringTokenizer tokenizer = new StringTokenizer("one two three");
    
    		while (tokenizer.hasMoreTokens())
    			System.out.println(tokenizer.nextToken());
    	}
    }

Student Performance and Statistics

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

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

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

Q1 0.7 / 1 Q2 0.9 / 1 Q3 0.8 / 1 Q4 0.8 / 1 Q5 0.4 / 1