🎯 Objective
Instructions:
Create a new Java file named
Countdown.java
. This is the class where you'll implement the countdown logic.In the
Countdown
class, define three methods:doWhileCountdown()
,whileCountdown()
, andforCountdown()
. Each method will implement the countdown using a different loop structure.Implement the
doWhileCountdown()
method using ado-while
loop,whileCountdown()
method using awhile
loop, andforCountdown()
method using afor
loop. Each method will count down from 10 to 1 and then print "Blastoff".Now, create another Java file named
CountdownApp.java
. This will contain yourmain
method, and you'll use it to create an instance of theCountdown
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:
Java class files
Screenshot of the Console with the code executing