Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.awt.Toolkit;
- import java.util.Timer;
- public class SnDBomb_v2
- {
- Toolkit tk;
- private static boolean isArmed;
- static Timer bombTimer;
- public SnDBomb_v2()
- {
- }
- public static void main(String[] args)
- {
- System.out.println("Password to arm the bomb: bomb.arm();");
- System.out.println("Password to disarm the bomb: bomb.disarm();");
- arm();
- }
- public static void arm()
- {
- // char[] pass = new char[]
- // {'b', 'o', 'm', 'b', '.', 'a', 'r', 'm', '(', ')', ';'};
- System.out.println();
- System.out.print("Enter password to arm the bomb: ");
- Scanner arm = new Scanner(System.in);
- String pass2 = arm.nextLine();
- if (pass2.equals("bomb.arm();"))
- {
- System.out.println("Bomb is armed.");
- setArmed(true);
- BombTask_v2 bt2 = new BombTask_v2();
- bombTimer = new Timer();
- bombTimer.schedule(bt2,5000);
- //bt2.run();
- // ((Runnable) bombTimer).run();
- disarm();
- }
- else
- {
- System.out
- .println("Error: Wrong password. Bomb not armed. Re-enter password.");
- arm();
- }
- }
- public static void disarm()
- {
- // char[] dpass = new char[]
- // {'b','o','m','b','.','d','i','s','a','r','m','(',')',';'};
- System.out.println();
- System.out.print("Enter password to disarm the bomb: ");
- Scanner disarm = new Scanner(System.in);
- String dpass2 = disarm.nextLine();
- if (dpass2.equals("bomb.disarm();"))
- {
- System.out.println("Bomb has been disarmed.");
- setArmed(false);
- bombTimer.cancel();
- }
- else
- {
- System.out
- .println("Error: Wrong password. Bomb still armed. Re-enter password.");
- disarm();
- }
- }
- public static boolean isArmed()
- {
- return isArmed;
- }
- public static void setArmed(boolean isArmed)
- {
- SnDBomb_v2.isArmed = isArmed;
- }
- /*
- * public static boolean checkAPW(char[] armed) { boolean isAPWCorrect = true;
- * char[] APW = { 'b', 'o', 'm', 'b', '.', 'a', 'r', 'm', '(', ')', ';' }; if
- * (armed.length != APW.length) { isAPWCorrect = false; } else { isAPWCorrect
- * = Arrays.equals(armed, APW); } return isAPWCorrect; }
- *
- * public static boolean checkDPW(char[] disarmed) { boolean isDPWCorrect =
- * true; char[] DPW = { 'b', 'o', 'm', 'b', '.', 'd', 'i', 's', 'a', 'r', 'm',
- * '(', ')', ';' }; if (disarmed.length != DPW.length) { isDPWCorrect = false;
- * } else { isDPWCorrect = Arrays.equals(disarmed, DPW); } return
- * isDPWCorrect; }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment