Computer Science 15-100 (Sections S-V), Fall 2008
Homework 10
Due:  Thu 13-Nov-2008 at 11:59pm (email copy) and at Friday's class/recitation (identical physical copy)
(no late submissions accepted).


Read these instructions first!


  1. ch4Exercises
  2. ch5Exercises
  3. SCALES Practice
    1. SCALES and the JCF
      1. List of Circles
      2. Map of Scores
    2. Mystery Methods
  4. Tetris (Part 2 of 2)
  5. Bonus/Optional:  Tetris Extensions

  1. ch4Exercises
    Read and study Chapter 4, sections 4.1 through 4.5 (so you are not responsible for sections 4.6 through 4.9).  Then, do the following Exercises from Chapter 4 (pp 200 - 201):
    Exercises 4.1,  4.3,  4.10,  4.12
     
  2. ch5Exercises
    Read and study Chapter 5, sections 5.1 through 5.8 (so you are not responsible for sections 5.9 through 5.12).  Then, do the following Exercises from Chapter 5 (pp 281 - 285):
    Exercises 5.11,  5.12 

    [ Note:  Exercises 5.1 through 5.10 (except 5.6) were assigned earlier this semester.  They are not assigned here, but you should review your solutions to those exercises. ]
     
  3. SCALES Practice
     
    1. SCALES and the JCF
       
      1. List of Circles
        In a file named Hw10ListOfCircles.java, write a program that displays a graphics window (by extending JComponentWithEvents) which starts out empty, but where the user can click anywhere in the window and a random filled circle will be added, centered at that location, with random radius (between 10 and 50) and random color (randomly chosen from the built-in colors, except not white (so it can be seen on the white background).  As the user clicks, the existing circles remain unchanged, so more and more circles become visible.  Each circle must be an instance of a Circle class that you create, and all the Circle instances must be stored in an ArrayList<Circle>, an instance variable in your Hw10ListOfCircles class.
         
      2. Map of Scores
        In a file named Hw10MapOfScores.java, write a program that reads in a file, Hw10MapOfScores.txt (watch the capitalization!), that contains a (very simplified) log of scores in a basketball game, where each line contains a player's name (without spaces) followed by the number of points scored on a given shot (one of 1, 2, or 3).  For example, here is a sample log file of a recently-played imaginary basketball game:
          Grace 1
          Blaise 2
          Grace 3
          Grace 1
          Zeb 1
          Blaise 2
          Alan 2
        Your program should maintain a map (as a HashMap<String, Integer>) that maps each player's name to his or her total score.  As a line is read, you should check if the player's name is already a key in the map.  If not, just add the name mapped to the given score.  But if the name is already in the map, then add the score to the score in the map and store that value in the map  Once the entire file has been read, create a list of names (as an ArrayList<String>), and place all names (that is, the keys in the map) into this array.  Then, sort this array.  Finally, using both the sorted array of names and the map of scores, print out an alphabetized list of each player followed by their total score.  For example, for the data given above, your program should print out:
          Alan 2
          Blaise 4
          Grace 5
           Zeb 1
        Note that this problem may be solved in several ways, but here you must use the approach described above (in particular, using the HashMap<String, Integer> and ArrayList<String> exactly as described).
         
    2. Mystery Methods
      In the written portion of your submission, answer the following questions in general, and in just a few words of plain English.
       
      1. In general, what does the following method do?

          public String f(String s, int i) {
            if ((s == null) || (i < 0) || (i >= s.length()))
              return s;
            String result = "";
            for (int j=0; j<s.length(); j++)
              if (i != j)
                result += s.charAt(j);
            return result;
          }
         

      2. In general, what does the following method do?

        Note:  This method calls method "f" from above.

          public boolean g(String s1, String s2) {
            if ((s1 == null) || (s2 == null))
              return false;
            for (int i=0; i<s1.length(); i++)
              if (s2.equals(f(s1,i)))
                return true;
            return false;
          }
         
  4. Tetris (Part 2 of 2)
    Starting from your Tetris code from last week, finish writing Tetris by following steps 5-7 in the notes for "Tetris for Intro/Intermediate Programmers".  Place the results in a file named Hw10Tetris.java.  While not strictly required, it is highly recommended that you follow the design spec as described in the document.  You should also add test methods wherever they are appropriate.
     
  5. Bonus/Optional:  Tetris Extensions
    Extend your Tetris implementation in interesting and compelling ways that (a) make the game more fun for players and (b) show off your hard-won programming skills.  Read part 8 of the Tetris notes for ideas, though you are not limited to these suggestions.  To receive proper credit, be sure to add a comment at the header of your Java program clearly listing each bonus feature you added, and also listing the total # of hours you invested in bonus (with the usual bonus rules applying).  Also:  please obtain instructor approval before going beyond 10 hours of bonus time on this assignment (this is not to discourage you (no!), but to be sure that all that time is invested in appropriate and credit-worthy activity).  Be creative!  Have fun!!!

Carpe diem!