[go: up one dir, main page]

0% found this document useful (0 votes)
9 views2 pages

Emmanuel Appiah Boateng Java Assignment

The document contains Java code for five programming tasks: a countdown program, a robot sound effect simulator, a battery level checker, a signal strength detector, and a light switch simulator. Each task includes a main method that implements specific functionality using loops and conditional statements. The code demonstrates basic programming concepts such as loops, conditionals, and output in Java.

Uploaded by

chuksottih
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Emmanuel Appiah Boateng Java Assignment

The document contains Java code for five programming tasks: a countdown program, a robot sound effect simulator, a battery level checker, a signal strength detector, and a light switch simulator. Each task includes a main method that implements specific functionality using loops and conditional statements. The code demonstrates basic programming concepts such as loops, conditionals, and output in Java.

Uploaded by

chuksottih
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Name: Emmanuel Appiah Boateng

Index Number: 1703708933


Group: D

Task 1: Countdown Program


java
public class Countdown {
public static void main(String[] args) {
// Initialize counter starting at 10
int number = 10;

// Continue looping while number is greater than or equal to 0


while (number >= 0) {
// Special case when we reach 0
if (number == 0) {
System.out.println("Launch!");
} else {
// Print current countdown number
System.out.println(number);
}
// Decrement counter by 1 each iteration
number--;
}
}
}

Task 2: Robot Sound Effect


java
public class RobotSound {
public static void main(String[] args) {
// Start at position 1
int position = 1;

// Loop through positions 1-8


while (position <= 8) {
// Check if position is even
if (position % 2 == 0) {
System.out.println("Beep"); // Even position sound
} else {
System.out.println("Boop"); // Odd position sound
}
// Move to next position
position++;
}
}
}

Task 3: Battery Level Checker


java
public class BatteryCheck {
public static void main(String[] args) {
// Start with empty charge (0%)
int charge = 0;

// Charge up to 25% in 5% increments


while (charge <= 25) {
// Determine charge level category
if (charge < 15) {
System.out.println("Low: " + charge + "%"); // Below 15%
} else {
System.out.println("High: " + charge + "%"); // 15% or above
}
// Increase charge by 5% each cycle
charge += 5;
}
}
}

Task 4: Signal Strength Detector


java
public class SignalCheck {
public static void main(String[] args) {
// Start with weakest signal (0Hz)
int signal = 0;

// Test signal strength up to 20Hz


while (signal <= 20) {
// Classify signal strength
if (signal < 12) {
System.out.println("Weak (" + signal + "Hz)"); // Weak signal
} else {
System.out.println("Strong (" + signal + "Hz)"); // Strong signal
}
// Increase signal by 4Hz each test
signal += 4;
}
}
}

Task 5: Light Switch Simulator


java
public class LightSwitch {
public static void main(String[] args) {
// Start with first cycle
int cycle = 1;

// Run through 7 cycles


while (cycle <= 7) {
// Determine if cycle is odd or even
if (cycle % 2 == 1) {
System.out.println("💡 On"); // Odd cycle - light on
} else {
System.out.println("◼ Off"); // Even cycle - light off
}
// Advance to next cycle
cycle++;
}
}
}

You might also like