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!
- Be sure to include your name, your Andrew ID, and your section clearly on the top of each file in your assignment.
- Also on the top of each file, include a timesheet logging all
the time you spent on that part of the assignment.
You will not be graded on your number of hours, but this information
will be helpful to the course staff.
- For non-programming problems
- Place all your solutions to the non-programming
problems in a single file named Hw10 (with whatever extension is appropriate
for the format you choose, such as Hw10.txt or Hw10.html, etc). You must
use a one of these file formats: plain text (txt), or RTF, or HTML, or
Word (doc, not docx), or PDF. No other file formats will be accepted.
- Show your work. Correct
answers without supporting calculations will not receive full credit.
- For programming problems:
- Place each solution in its own file named exactly as given below, and
with a class name that exactly matches the file name. So if the file
name is Hw10Foo.java, the main class in that file must be Hw10Foo.
- Use well-named variables, proper indenting, reasonable commenting,
etc.
- What to submit
- Either one zip file, Hw10.zip, containing all your files (this is
preferred), or all the files as attachments to a single email (do not send
one email per file!). It is recommended
that you "cc" yourself in that email, too, just to confirm that you properly
sent the email.
- ch4Exercises
- ch5Exercises
- SCALES Practice
- SCALES and the JCF
- List of Circles
- Map of Scores
- Mystery Methods
- Tetris (Part 2 of 2)
-
Bonus/Optional: Tetris
Extensions
- 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
- 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. ]
- SCALES Practice
- SCALES and the JCF
- 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.
- 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).
- Mystery Methods
In the written portion of your submission, answer the following
questions in general, and in just a few words of plain
English.
- 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;
}
- 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;
}
- 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.
-
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!