Programming Assignment 04


Due: Week of Sep. 19 in lab


  1. Problem 1.3.11 on page 78 of your book. Name the file and program ch1sec3prob11.java. Worth 10pts. Do not output any values of 2^N. When using Math.log(N) immediately cast down to an int type.
    Examples:
    • Input:$ java ch1sec3prob11
      Output:
      log NNN log NN^2N^3
      2 16 32 256 4096
      3 32 96 1024 32768
      4 64 256 4096 262144
      4 128 512 16384 2097152
      5 256 1280 65536 16777216
      6 512 3072 262144 134217728
      61024 614410485761073741824
      720481433641943048589934592
  2. Problem 1.3.27 on page 81 of your book. Name the file and program ch1sec3prob27.java. Worth 20pts. Take N as a command-line argument.
    Examples:
    • Input:$ java ch1sec3prob27 4
      Output:
       * *
      * * 
       * *
      * * 
    • Input:$ java ch1sec3prob27 5
      Output:
       * * 
      * * *
       * * 
      * * *
       * * 
  3. Write a program which takes a single String (no spaces) from standard input. First, your program should remove all duplicate letters (Hint: use substring() to decompose a string and concatenation to recompose it). Second, your program should reverse the String (Hint: convert the String to a char[] with toCharArray()). Last, output the modified string. Name the file and program ch1sec4prob00.java. Worth 30pts. You cannot use the Java class/utility StringBuilder. Also note that 'e' is NOT a duplicate of 'E'.
    Examples:
    • Input:$ java ch1sec4prob00
      Output:(user enters string after prompt...)
      Enter a string without spaces: Hello
      oleH
    • Input:$ java ch1sec4prob00
      Output:(user enters string after prompt...)
      Enter a string without spaces: elephAntwalk
      kawtnAhple
  4. Problem 1.4.30 on page 118 of your book. Name the file and program ch1sec4prob30.java. Worth 40pts. Take M, N, and p as command-line arguments in that order. Hint: you only need a single multidimensional array of booleans to solve this problem, the output is analysis of those booleans.
    Examples:
    • Input:$ java ch1sec4prob30 3 5 0.2
      Output:
      .*.*.
      .....
      **...

      1*2*1
      33311
      **100
    • Input:$ java ch1sec4prob30 8 3 0.5
      Output:
      ***
      **.
      ...
      .**
      .**
      ...
      ...
      .*.

      ***
      **3
      343
      2**
      2**
      122
      111
      1*1
  5. Bonus. Problem 1.5.19 on page 157 of your book. Worth 10 pts. However, each way you improve the solution beyond the basic specification will earn you more points. Be sure to write comments in your program about how it is improved. Ideas include animating the drawing of the lines infinitely, making the lines have an artistic coloring, or allowing keyboard input to alter the probability p. Name your file and program ch1sec5prob19bonus.java.
    Examples:
    • Input:$ java ch1sec5prob19bonus 20 .33
      Output:


Grading

Each assignment is graded out of 100% based on a combination of the criteria listed in the assignment description and programming style (e.g., good comments and naming) -- following instructions is extremely important in computer science, train yourself to think like the computer; programming style is important to be able to communicate your solutions to another programmer; both of which you are graded upon.

Specific instructions. Failure to do these steps will result in a loss of points.

Turn in instructions. Each programming assignment is to be turned in before your lab section. You will turn in a soft copy of the assignment (.java or .zip for multiple java files) through blackboard. You will also turn in a hard copy of the assignment in your lab section with a signed coverpage (each program should start a new page of the hard copy).

If there are any discrepencies in grades please see the instructor during his office hours or by appointment (do not discuss with the lab assistants or graders).