Commit 8e207141 authored by tammam.alsoleman's avatar tammam.alsoleman

Build_AscendingHacker_Class

parent 2b4bbf01
package PACKAGE_NAME; public class DescendingHackerThread extends Thread {
private Vault vault;
public class DescendingHackerThread { public DescendingHackerThread(Vault vault) {
} this.vault = vault;
this.setName("DescendingHacker");
this.setPriority(Thread.MAX_PRIORITY);
}
@Override
public void run() {
System.out.println(this.getName() + " started hacking from 9999 to 0");
// Try every number from 9999 down to 0
for (int guess = 9999; guess >= 0; guess--) {
if (vault.isCorrectPassword(guess)) {
System.out.println(this.getName() + " cracked the vault! Password: " + guess);
System.exit(0);
}
}
System.out.println(this.getName() + " finished but didn't find the password!");
}
}
\ No newline at end of file
public class Main { public class Main {
public static void main(String[] args) {
System.out.println("Vault Hacking Race Started!");
// Create a vault with random password
Vault vault = new Vault();
AscendingHackerThread ascendingHacker = new AscendingHackerThread(vault);
DescendingHackerThread descendingHacker = new DescendingHackerThread(vault);
PoliceThread police = new PoliceThread();
System.out.println("Starting all threads...");
ascendingHacker.start();
descendingHacker.start();
police.start();
System.out.println("All threads are running !");
}
} }
\ No newline at end of file
package PACKAGE_NAME; public class PoliceThread extends Thread {
public class PoliceThread { public PoliceThread() {
} this.setName("Police");
}
@Override
public void run() {
System.out.println("Police are on the way! 10 seconds remaining...");
// Countdown from 10 to 1
for (int i = 10; i > 0; i--) {
try {
// Wait for 1 second (1000 milliseconds)
Thread.sleep(1000);
System.out.println(i + " seconds remaining...");
} catch (InterruptedException e) {
System.out.println("Police thread was interrupted!");
e.printStackTrace();
}
}
// If we reach here, time is up and police arrived
System.out.println("Game over for you hackers! Police arrived!");
System.exit(0); // End the entire program
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment