210 Homework Assignments

Summer 2001

Homework must be typed (unless specified otherwise) and will be collected at the beginning of class on the date the homework is due. No homework will be accepted after 2:00 p.m. on the day the homework is due.

If you are unable to come to class you may submit your homework at the class meeting before it is due or send the homework with another student. If you have an excused absence and turn the homework in late, the number of homeworks averaged will not include that homework.

Homework must be typed to be accepted. If more than one page is turned in, the pages must be stapled together.

Homework is to be done individually. The purpose of the "read and outline" homework is to make it possible to cover the course material in five weeks. Thus, it is important that each person read and write for themselves. If the instructor believes that homework has been jointly written, on the first occurrence the grade will be shared jointly among the writers. A second occurrence will be considered academic dishonesty and appropriate action will be taken.


#1 (due Wednesday, May 23) 10 pts.

Read Chapter 1 of Java Elements and write an outline of the material in this chapter. Your outline should be about two typed, single-spaced pages in length and should contain references to all the major points covered in the chapter as well as examples and citations as appropriate. You will also use this outline as a study guide when studying for the Hour Quiz and the Exam, so make it useful to yourself. (8 pts.)

Include your solution to Problem 1.4 on pages 34-35 (2 pts.)

#2 (due Thursday, May 24) 10 pts.

Read Chapter 2 of Java Elements and write an outline for Chapter 2. (8 pts.) Do not use the Console Window. Instead, use the ReadStream and PrintStream Classes, pages 334-335 of Java Structures. Do use the Drawing Window.

Explain (one statement at a time, using a drawing at each stsep) how the code on page 57 draws the picture in Figure 2.7 (2 pts.)

#3 (due Friday, May 25) 10 pts.

Read Chapter 3 of Java Elements and write an outline for Chapter 3. (8 pts.) Write code to produce the drawing in Problem 3.13 on page 94 (2 pts.)

#4 (due Monday, May 28) 10 pts.

Read Chapter 4 of Java Elements and write an outline for Chapter 4 (8 pts.) Include code for a method that tests to see if two rectangles (Rect) overlap (2 pts.).

#5 (due Tuesday, May 29) 10 pts.

Read Chapter 5 of Java Elements and write an outline for Chapter 5 (6 pts.) In code for the solution of problem 5.3 on page 143 (4 pts.). (It is suggested that you check your solution by running it.) Remember that code must be typed. Examples of problem 5.3 are given:
          Adding one to the String "abcd" yields "abce".
          Adding one to the String "abcz" yields "abda" because of the carry.
          Adding one to the String "z" yields "aa" because of the carry.
          Adding one to the String "aaaa" yields "aaab".

          public static String addOneToWord ( String word )
          // pre: the word contains only lower case letters
          // post: the rightmost letter is incremented to the next letter
          //       a -> b -> c -> ... -> x -> y -> z -> a
          //       and addition to 'z' generates a carry

#6 (due Wednesday, May 30) 10 pts.

Read Chapter 6 of Java Elements and write an outline for Chapter 6 (7 pts.). Write code for problem 6.3 on page 158 (3 pts.). Examples of removing double letters from a word:
          "noon" becomes "non"
          "mississippi" becomes "misisipi"
          "szzzzzzz" becomes "sz"
 
          public static String removeDoubles ( String word )
          // pre: word.length() >= zero
          // post:  returns word with all double characters removed

#7 (due Thursday, May 31) 10 pts.

Read Chapter 7 of Java Elements and write an outline for Chapter 7 (5 pts.) The following methods apply to a 3x3 tic-tac-toe board. Complete the following methods (5 pts.). (These methods do NOT use the Drawing Window.)
          public static void tictactoeInit (char [] [] board)
          // post:  initializes a 3x3 board to all blanks.
  
          public static void play (char [] [] board, int x, int y, char symbol)
          // pre:  board [x][y] contains a blank
          // post:  board [x][y] is set to symbol

          public static boolean diagonal (char [] [] board, char symbol)
          // post:  returns true if either diagonal contains only symbol
          //       otherwise, returns false

Friday, June 1 -- Hour Quiz 1


#8 (due Monday, June 4) 10 pts.

Read Chapter 8 of Java Elements and write an outline for Chapter 8 (8 pts.) Include an answer to exercise 8.2 (2 pts.) on page 234 (What is an "abstract data type" and why is it considered an improvement over systems that don't support data abstraction?)

#9 (due Tuesday, June 5) 10 pts.

We have mentioned that a two-dimentional matrix is actually stored as a one-dimensional array. Assume an array that is declared by
          int [][] matrix = new int [m][n]

can be thought of as having subscripts

          [0][0]    [0][1]    [0][2]    [0][3]   ...   [0][n-1]
          [1][0]    [1][1]    [1][2]    [1][3]   ...   [1][n-1]
          [2][0]    [2][1]    [2][2]    [2][3]   ...   [2][n-1]
           ...
          [m-1][0]  [m-1][1]  [m-1][2]  [m-1][3] ...   [m-1][n-1]
    
Then, if the array is stored in row-major order

          [0][0] maps to [0] in the linear array
          [0][1] maps to [1] in the linear array
           ...
          [1][0] maps to [n]
          [1][1] maps to [n+1]
          etc.

Let us suppose that we have a class

          public class Matrix 
          {
             private int [] linearArray;
             private numRows;
             private numCols;

             private Matrix ( int m, int n )
             // creates a linear array to logically imitate an mxn matrix
             {
                linearArray = new int [ m * n ];
                numRows = m;
                numCols = n;
             }

             public void store ( int item, int x, int y )
             // mimics assignment:  matrix [x][y] = item;

             public int retrieve ( int x, int y )
             // returns the item at logical location matrix [x][y]
          }
Write code for the two methods, store and retrieve.

#10 (due Wednesday, June 6) 10 pts.

Read Chapters 10 and 11 of Java Elements and submit answers to the following questions.

#11 (due Thursday, June 7 ) 10 pts.

Read Chapters 0, 1, and 2 of Java Structures and write a synopsis of the important points in these chapters.(8 pts.) Write a main program that will create two instances of Association. m Use idnumber as the key (You will need to wrap it in an Integer.) and use a String containing a person's name as the value. In your main program write code which will execute each of the Association methods. (2 pts.) It is not necessary to compile your code, but your code is more likely to be correct if you do.

#12 (due Friday, June 8) 10 pts.

Read Chapter 3 (Vectors) of Java Structures and write a synopsis of the important point in this chapter. (8 pts.) The Vector interface is given on page 36. List the methods of the interface and, for each method, give the growth rate of the algorithm using N = the number of items stored in the Vector. (2 pts.)




Return to Eleanor Hare's home page.

Return to Department of Computer Science Home page.