Topics covered on the 2nd midterm: Chapters 1 through 7 emphasis on one-dimensional arrays (Chapter 6) and two-dimensional arrays (chapter 7). The exam is closed book, without notes.

General instructions: write all your answers on the exam. All questions will ask you to write methods, either static (class) methods, or instance (non-static) methods that access instance variables of a class.

None of the methods you write should read from the console or write to the output screen (in particular, there should be no calls to System.out in your solutions). None of the questions will involve applets or swing applications. Read the questions carefully.

For questions involving strings, you may find the following methods useful:

You can expect about 4 questions on the exam. The following questions would be typical.

  1. Write a static method
    public static int longestBlank(String str)
    that returns the maximum number of consecutive blanks in the String parameter str. For example, if the string is "abc def geh ijk", the method would return 2. If there are no blanks in the string, it returns 0.

  2. Write a static method
           public static String shortest(String[ ] words)
    that returns the string in the array that has the shortest length. If there are more than one string that has the shortest length, the method should return the first one encountered. If the array contains: "Hello", "this", "is", "a" and "test", the method should return the string "a". Remember that the elements of the array are words[0] through words[k], where k is one less than words.length, the length of the array (no parentheses, since this is not a method call).

    Consider the following class and its instance variables:
    public class Bingo
    {   //   methods go here.....
        int size;     // these are instance variables
        char [ ][ ] board = new board[size][size];;
  3. This question refers to class Bingo. Write a method (an instance method)
          public boolean rowBingo(char c)
    that returns true if board has at least one row where no element in the row is the character given by the parameter c. Otherwise it returns false. (The first index of the array is the row index and the dimensions of the array are size by size.)
  4. This question also refers to class Bingo. Write a method (an instance method)
          public boolean theSame()
    that returns true if at least one row in the array board is the same as the first row. Otherwise it returns false. For instance in
        4  8  3  4
        3  5  5  1
        4  8  3  4
        9  2  4  9

    The 3rd is the same as the first row, so the method returns true.