Computer Science 202
Introduction to Programming

Fall 2013, The College of Saint Rose

Countdown BlueJ Project

Click here to download a BlueJ project for Countdown.


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 2228 2013-10-24 05:42:15Z 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!");
    }
}