CIT 591 Assignment 10: Drake
Equation
Fall 2008, David Matuszek

Are there really intelligent alien civilizations? If so, how many, and can we ever communicate with them?
The Drake equation supplies the answers to these questions. Your assignment is to develop code to compute two versions of the Drake equation (Drake's, and mine), and to implement three different interfaces to that code.
From the article Drake Equation in Wikipedia:
|
The Drake equation states that:
where:
and
|
However, this is just for our own galaxy.
We will use this equation as is, but we will also introduce a second,
modified version of the equation:
|
This equation has been modified in two ways. First, I have added
the factor G, to represent the number of galaxies in the
universe. Second, I have removed the factor
fc, on the assumption that, even if life does exist
in other galaxies, it is much too far away for us to ever hear their radio
signals. N, therefore, is the total of all intelligent
civilizations that exist "now", not just those with which we might
communicate.
|
Some numbers:
|
Create a package drake with the following three classes in it.
DrakeEquation classWrite a class DrakeEquation to compute the equations given
above. It should have the following setter methods:
| Factor | Setter method |
|---|---|
|
R*
|
void setStarFormationRate(long) |
|
fp
|
void setFractionWithPlanets(double) |
|
ne
|
void setAverageHabitablePlanets(double) |
|
fl
|
void setFractionWithLife(double) |
|
fi
|
void setFractionWithIntelligence(double) |
|
fc
|
void setFractionWithCommunication(double) |
|
L
|
void setExpectedLifetime(long) |
(G is not included in this list because its value is reasonably well known, and can be hard-wired into the program.)
The setter methods should throw an IllegalArgumentException
(which is a RuntimeException) if they are given illegal values.
(All values should be non-negative, and fractions should be less than or
equal to 1.) Write JUnit tests for this.
DrakeEquation should have the following getter
methods:
| Getter method | What it returns |
|---|---|
double getLifeInGalaxy()
|
The number of planets in our galaxy that have life: LG = SG× fp × ne × fl |
double getCommunicatingCivilizations()
|
Result of applying the Drake equation: The number of intelligent civilizations in our galaxy with which we might possibly communicate. |
double getLifeInUniverse()
|
The number of planets in the entire universe that have life: LU = SG × G × fp × ne × fl |
double getIntelligenceInUniverse()
|
Result of applying the modified Drake equation: The number of intelligent civilizations in the entire universe. |
Each of these methods should throw an IllegalStateException
(which is a RuntimeException) if they are called before all the
variables they use have been given a value. (One way to test for this is to
initialize all variables to -1.) Your unit tests should check
for this. For other testing, set the input variables, get the output result,
and test whether it is correct. You should test whether extreme cases are
handled correctly.
There are three user interface classes, for reasons that I will explain in
a moment. Each of these has a main method, so that the program
can be run starting from any one of these classes. Since all of these methods
do input/output, do not write unit tests for any of them.
DrakeTextUI classThis class does text-only input and output. Ask the user for the value of
each input factor; if any exception occurs, catch it, print a helpful error
message, and tell the user to try again. Use the nextDouble
method in java.util.Scanner to do input.
All the getter methods return double values. However, any
numbers greater than one and less than Long.MAX_VALUE should be
cast to long before printing.
When all values have been input, the values for both sets of equations (our galaxy and entire universe) should be printed out (with explanatory text).
DrakeGUI classThis class uses a Swing GUI to interact with the user. After all the
necessary fields have been filled in, the user can press a button to compute
the (original) Drake equation and see the results for our
galaxy. All normal
interaction should take place in a single (JFrame) window; use
dialogs to warn the user of missing (blank) or illegal values.
All the getter methods return double values. However, any
numbers greater than one and less than Long.MAX_VALUE should be
cast to long before printing.
The program should quit when the user clicks a "Quit" button or closes the main GUI window.
ModifiedDrakeGUI classThis class uses a Swing GUI to interact with the user. After all the
necessary fields have been filled in (not including
fc, which is not used), the user can press a button
to compute the modified Drake equation and see the results for the entire
universe.
All normal interaction should take place in a single (JFrame)
window; use dialogs to warn the user of missing (blank) or illegal values.
All the getter methods return double values. However, any
numbers greater than one and less than Long.MAX_VALUE should be
cast to long before printing.
The program should quit when the user clicks a "Quit" button or closes the main GUI window.
All exceptions should be handled. Nobody likes a program
that crashes. Some exceptions will come from the
DrakeEquation class; others will come from entering
non-numeric values when a number is required.
DrakeGUI and ModifiedDrakeGui, receive an exception,
they should put up a JOptionPane message dialog to inform the user of the
problem. They should also blank out the offending text entry.DrakeTextUI, receives an exception,
it should print a message to the user and ask the user to enter a replacement
value. Work together with your partner to complete the DrakeEquation
and DrakeTextUI classes. However, each of you should
individually write one of the two GUI classes. Both need to be done,
so agree with your partner which of you does which GUI (they are of equal
difficulty). Be sure to use the @author tag or tags in every
class.
My goal is that each of you gets experience constructing a GUI. Please do the initial design and programming by yourself. If you run into difficulties, you can get help from your partner, but first get as far as you can by yourself.
When your GUI is completed, it is a good idea to show it to your partner, to find out whether using it is as obvious as you undoubtedly think it is.
If you have no partner, you can omit the ModifiedDrakeGUI
class.
Grading will be based on correct functioning, good code style, and
reasonable GUI appearance and comprehensibility. In this assignment you and
your partner may receive different grades, as each of you has primary
responsibility for one of the GUI classes. (Each GUI class should have
one @author tag, naming its one author; other classes should
have two @author tags, unless you have no partner.)
As usual, turn in one zip file for the partnership containing all necessary Java files. Due Thursday, November 20, before midnight.