Introduction |
This programming assignment is designed to ensure that you know how to
write programs that use pre-written classes, including classes that read
input files (even multiple files in a single program) and write output
files.
The constructors and methods for these classes are are documented in Javadoc,
which you are expected to read during this assignment.
Of course, you will continue gaining experience with the standard control
structures in Java and will have the opportunity to explore using the
debugger on these programs.
Finally, you'll continue to practice writing, testing, and debugging
programs using iterative-enhancement.
You will write two programs in this assignment. As always, you can check the behavior of your programs against mine by downloading and running my Executables, to help you understand the specification of the problem and observe the programmer/user interaction you are to implement The cardiac program includes various data files. Because this assignment is straightforward, concentrate on using good programming style. Pay particularly close attention to the style principles discussed in the Coding Style lecture.
Write each program in its own project folder: you should name them accordingly (e.g., dicewar and cardiac); then put both folders in another folder whose name combines your names (when programming in pairs) and the program number (e.g., pattis-stehlik-3). Then zip this folder and dropoff that single zip file. Each pair should submit one project: either partner can submit it.
|
Dice War |
Write a program that simulates playing games of dice war; the program should
also collect certain statistics while it is playing these games and report
them after the required number of games have been played.
In a game of dice war, each player starts out with his/her own dice (2,
6-sided) and some number (entered by the user) of chips.
Each player roles his/her dice.
If one player's pip sum is higher, that player gets a chip from the other
player.
Whenever one player has no chips left, the game is over (and that player
has lost; and the other player has won).
Your program must prompt the user for the number of games to play, and the number of chips with which the players start each game. It also prompts the user to determine if the program's behavior is to be traced. The program then simulates that many games of dice war, using object constructed from the DiceEnsemble class: one pair of dice for each player. It keeps track of the number of times each player wins, the length (number of dice rolls) of the shortest and longest games, and the total number of dice rolls (over all the games). It also uses a Timer to keep track of how long (in clock-time) it takes to play all the games. Try to use the DiceEnsemble objects themselves to keep track of some of the required information, so you do not have to declare extra variables. Ultimately the program prints
For this assignment, try to work out your own enhancements. A starting point could be writing a program to play one game (with the user supplying the number of starting chips); then add tracing; then add playing multiple games (with the user supplying the number); then add code for keeping all the statistics; then add timing the game. Explore the DiceEnsemble and Timer classes, and use them effectively to minimize the variables and code you must write. I found Integer.MAX_VALUE (check out this static final field in the Integer wrapper class in Javadoc) useful as an initialization for computing the smallest-length game. |
Implantable Cardiac Defibrillators |
Write a program that simulates the working of an
Implantable Cardiac Defibrillator (ICD).
An ICD is a small electronic device placed in the chest cavity of a patient
who is suffering from arrhythmias (heartbeat irregularities).
This device constantly monitors the electrical output of a beating heart:
if it detects a bradycardia (heart beating too slowly) it acts a pacemaker;
more importantly, if it detects a tachycardia (heart beating too fast to
pump blood effectively: in extreme cases this results in ventricular
fibrillation) at which point it acts as a defibrillator by supplying a
large shock to the heart in an attempt to restore a normal rhythm.
This shock is described by patients as feeling like a kick in the chest
-although many patients are unconscious by the time action is taken on
the detected arrhythmia.
If you are interested, you can read more detailed information on
ICDs.
The basic algorithm inside an ICD computes the zero-crossing count (ZCC) of the electical signals it samples while it is monitoring a heart. Each signal should be between the value of -100 and +100 inclusive (if not, the ICD is receiving faulty signals, and it should shut itself off). During an interval (typically lasting a few seconds), whenever the signal value goes from positive to negative or negative to positive, the ICD increments its ZCC. For the purposes of this assignment, we will treat 0 as a positive number. At the end of an interval, the ICD checks to see whether its ZCC is within a normal range: in a bradycardia the ZCC is too low (equals or falls below some threshold); in a tachycardia the ZCC is to high (equals or exceeds some threshold). If the ICD detects either of these conditions it takes the necessary action; then it resets the ZCC and samples the heart signals for another interval. Of course, real ICDs have evolved to exhibit much more sophisticated behaviors.
For example, if the ICD is using an interval length of 10, the
following table labels each sample, shows the signal value for that sample,
and the current ZCC.
This program will simulate the simple ICD algorithmg, allowing us to test it on various data files that represent samples taken of the actual electrical signals of a monitored heart. It should operate as follows
|
Extra Credit |
The dice war problem has 1 point of extra credit.
To earn it, at the bottom of the main comment, include a section
labelled Extra Credit.
In this section, estimate the average number of dice rolls for a game
where each player starts out with 1,000,000 chips.
Explain the details of how you arrived at your estimate.
Do not discuss your estimate with anyone but the student you are pairing with. |