CIT 591 Assignment 8: Drake Equation (two versions)
Fall 2005, David Matuszek

Purposes of this assignment:

General idea of the assignment:

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:

N = R* × fp × ne × fl × fi × fc × L

where:

N is the number of extraterrestrial civilizations in our galaxy with which we might expect to be able to communicate

and

R* is the [yearly] rate of star formation in our galaxy
fp is the fraction of those stars which have planets
ne is average number of planets which can potentially support life per star that has planets
fl is the fraction of the above which actually go on to develop life
fi is the fraction of the above which actually go on to develop intelligent life
fc is the fraction of the above which are willing and able to communicate
L is the expected lifetime [in years] of such a civilization

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:

N = G × R* × fp × ne × fl × fi × L

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:

  • Astronomers' best estimate of R* are in the range of 5 to 20 per year.

  • Our own solar system has from 8 to 12 or 15 planets, depending on what you want to call a planet.

  • So far we can only detect very large planets in nearby star systems, in most cases just the one largest planet. As of October 2005, there are 173 such planets.

  • The number of stars in a galaxy is typically from 107 to 1012, and is about 1011 on average. (This number is not used in the above equations.)

  • The best estimate for G (number of galaxies in the universe) is 1011.

  • The rest of the numbers are anyone's guess.

The DrakeEquation class

Write 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
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
double getIntelligenceInUniverse()
Result of applying the modified Drake equation: The number of intelligent civilizations in the 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.

The user interface classes:

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.

The DrakeTextUI class

This 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 of both equations should be printed out (with explanatory text).

The DrakeGUI class

This 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 result. 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.

The ModifiedDrakeGUI class

This 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 result. 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.

Assignment:

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 and due date:

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.)

Due date:

As usual, turn in one zip file for the partnership containing all necessary Java files. Due Thursday, November 3, before midnight.