CS100 M Fall 2003
More Review/Practice Questions for Final Exam

Note:
Be sure to review the all the homework questions and their solutions as part of your preparation for the final exam. Review the three prelims and the prelim review questions.

Question 1
Programming Project 6.4 in Lewis & Loftus (page 375)

Question 2
Write a Java static method sum2dArray to perform an operation similar to sum(matrix') in MATLAB. Method sum2dArray takes as input argument (a reference to) a 2-d array of type double, sum up each "row" of the array, and return (the reference to) a 1-d array that contains all the row sums. The 2-d array may be ragged. Write a method call to use method sum2dArray.

Question 3
Part A:   Given a 2-d array x of floating point numbers, write a Java program fragment to re-order the rows such that the row sums are in ascending order. You may assume that all rows exist. You may call method select_sort that you wrote for Exercise 5 to do the sorting. (Or you may write the method select_sort again for practice!)
Part B:   Given a 2-d array x of floating point numbers, write a Java program fragment to re-order the columns such that the column sums appear in ascending order. Recall that 2-d array x is in row-major order. You may assume here that x is a rectangular array.

Question 4
Review class Room and its subclass Bathroom discussed during Lecture 25 (see notes on 11/25). Assume that the client code is written in a class called House in the main method. Answer the following questions:
  1. Which variables and methods are inherited?
  2. Write an overloaded method majorCleanUp in class Bathroom that takes as the input argument the number of times to callmethod clean in class Room.
  3. Write a client class MyHouse that performs similar operations as shown in the client code given in Lecture 25. Instead of creating three Room objects with separate reference variables r1, r2, and r3, use an array of objects.
  4. For practice, design another subclass of Room. Then modify your client class MyHouse to use your new subclass.
If you haven't already played with classes Room and Bathroom as I suggested in lecture, do it now! Consider the client code given in lecture, first predict the output and then run the code to confirm your predictions. Furthermore, make changes to the code, predict the output, and run the code again to confirm.

Question 5
What is the output of the following program?
class Data0 {
  private int m;
  public Data0 d0;

  public Data0(int num) {
    m = num;
  }

  public int get_val() {
    return m+d0.m;
  }
} //class Data0

class Data1 extends Data0 {
  private int n;

  public Data1(int x, int y) {
    super(x);
    n = y;
  }

  public int get_val() {
    return n+super.get_val();
  }
} //class Data1

public class Review {
  public static void main(String[] args) {
    Data0 dat0 = new Data0(0);
    Data1 dat1 = new Data1(1,2);
    dat0.d0 = new Data0(3);
    dat1.d0 = new Data1(4,5);
    dat1.d0.d0 = new Data0(6);
    System.out.println(dat0.get_val());     //________
    System.out.println(dat1.get_val());     //________
    System.out.println(dat1.d0.get_val());  //________
  }
} //class Review

Question 6
Write a Java program fragment to find the frequencies of all vowels in a given String (referenced by variable) str. Store the frequencies in a vector of length 5. For example, the string
  I loVE prOgramming
has the following vowel frequencies:
  a  e  i  o  u
  1  1  2  2  0