Module 2 - Lab - Countdown

 Objective

Instructions:

  1. Create a new Java file named Countdown.java. This is the class where you'll implement the countdown logic.

  2. In the Countdown class, define three methods: doWhileCountdown(), whileCountdown(), and forCountdown(). Each method will implement the countdown using a different loop structure.

  3. Implement the doWhileCountdown() method using a do-while loop, whileCountdown() method using a while loop, and forCountdown() method using a for loop. Each method will count down from 10 to 1 and then print "Blastoff".

  4. Now, create another Java file named CountdownApp.java. This will contain your main method, and you'll use it to create an instance of the Countdown class and call each of its methods.

Here's the Java code that meets the above requirements:

 

CountdownApp.java code starter:

public class CountdownApp { public static void main(String[] args) { Countdown countdown = new Countdown(); // Run the do-while countdown countdown.doWhileCountdown(); // Run the while countdown countdown.whileCountdown(); // Run the for countdown countdown.forCountdown(); } }

Expected Output:

10 9 8 7 6 5 4 3 2 1 Blastoff! 10 9 8 7 6 5 4 3 2 1 Blastoff! 10 9 8 7 6 5 4 3 2 1 Blastoff!

 

 Deliverables

Upload the following files in a zip folder that you have created:

  1. Java class files

  2. Screenshot of the Console with the code executing

 

COSC-1437 / ITSE-2457 Computer Science Dept. - Author: Dr. Kevin Roark