Computer Science 202
Introduction to Programming

Fall 2012, The College of Saint Rose

Countdown BlueJ Project

Click here to download a BlueJ project for Countdown.


Download file: Countdown.vls


Countdown Source Code

The Java source code for Countdown is below. Click on a file name to download it.


Countdown.java

/*
 * Example Countdown: count down from a given number to a Blastoff!
 *
 * Jim Teresco, The College of Saint Rose, CSC 202, Fall 2012
 *
 * $Id: Countdown.java 1937 2012-10-08 18:06:13Z terescoj $
 */

import javax.swing.JOptionPane;

public class Countdown {

    public static void main(String[] args) {
        
        // read in the starting number for our countdown
        int countdownLength = 0;
        do {
            String input = JOptionPane.showInputDialog("Enter a (positive) number for the start of the countdown");
            countdownLength = Integer.parseInt(input);
        } while (countdownLength <= 0);
    
        // now we count down
        for (int seconds = countdownLength; seconds > 0; seconds--) {
            JOptionPane.showMessageDialog(null, seconds + "...");
        }
        
        // and finally, it's Blastoff!
        JOptionPane.showMessageDialog(null, "Blastoff!");
    }
}