bowlingdude47

SnDBomb_v2

Sep 12th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.awt.Toolkit;
  3. import java.util.Timer;
  4.  
  5. public class SnDBomb_v2
  6. {
  7. Toolkit tk;
  8. private static boolean isArmed;
  9. static Timer bombTimer;
  10.  
  11. public SnDBomb_v2()
  12. {
  13.  
  14. }
  15.  
  16. public static void main(String[] args)
  17. {
  18. System.out.println("Password to arm the bomb: bomb.arm();");
  19. System.out.println("Password to disarm the bomb: bomb.disarm();");
  20. arm();
  21.  
  22. }
  23.  
  24. public static void arm()
  25. {
  26. // char[] pass = new char[]
  27. // {'b', 'o', 'm', 'b', '.', 'a', 'r', 'm', '(', ')', ';'};
  28. System.out.println();
  29. System.out.print("Enter password to arm the bomb: ");
  30. Scanner arm = new Scanner(System.in);
  31. String pass2 = arm.nextLine();
  32. if (pass2.equals("bomb.arm();"))
  33. {
  34. System.out.println("Bomb is armed.");
  35. setArmed(true);
  36. BombTask_v2 bt2 = new BombTask_v2();
  37. bombTimer = new Timer();
  38. bombTimer.schedule(bt2,5000);
  39. //bt2.run();
  40. // ((Runnable) bombTimer).run();
  41. disarm();
  42. }
  43. else
  44. {
  45. System.out
  46. .println("Error: Wrong password. Bomb not armed. Re-enter password.");
  47. arm();
  48. }
  49. }
  50.  
  51. public static void disarm()
  52. {
  53. // char[] dpass = new char[]
  54. // {'b','o','m','b','.','d','i','s','a','r','m','(',')',';'};
  55. System.out.println();
  56. System.out.print("Enter password to disarm the bomb: ");
  57. Scanner disarm = new Scanner(System.in);
  58. String dpass2 = disarm.nextLine();
  59. if (dpass2.equals("bomb.disarm();"))
  60. {
  61. System.out.println("Bomb has been disarmed.");
  62. setArmed(false);
  63. bombTimer.cancel();
  64. }
  65. else
  66. {
  67. System.out
  68. .println("Error: Wrong password. Bomb still armed. Re-enter password.");
  69. disarm();
  70. }
  71. }
  72.  
  73. public static boolean isArmed()
  74. {
  75. return isArmed;
  76. }
  77.  
  78. public static void setArmed(boolean isArmed)
  79. {
  80. SnDBomb_v2.isArmed = isArmed;
  81. }
  82.  
  83. /*
  84. * public static boolean checkAPW(char[] armed) { boolean isAPWCorrect = true;
  85. * char[] APW = { 'b', 'o', 'm', 'b', '.', 'a', 'r', 'm', '(', ')', ';' }; if
  86. * (armed.length != APW.length) { isAPWCorrect = false; } else { isAPWCorrect
  87. * = Arrays.equals(armed, APW); } return isAPWCorrect; }
  88. *
  89. * public static boolean checkDPW(char[] disarmed) { boolean isDPWCorrect =
  90. * true; char[] DPW = { 'b', 'o', 'm', 'b', '.', 'd', 'i', 's', 'a', 'r', 'm',
  91. * '(', ')', ';' }; if (disarmed.length != DPW.length) { isDPWCorrect = false;
  92. * } else { isDPWCorrect = Arrays.equals(disarmed, DPW); } return
  93. * isDPWCorrect; }
  94. */
  95. }
Advertisement
Add Comment
Please, Sign In to add comment