Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. public class LockDataStructureClass
  2. {
  3. private int xNum;
  4. private int yNum;
  5. private int zNum;
  6. private int dial;
  7. private int lid = 0; // lid is top
  8. public static boolean sealed = false; // sealed is locked
  9.  
  10. public LockDataStructureClass()
  11. { //default constructor
  12.  
  13. }
  14.  
  15. public LockDataStructureClass(int xNum, int yNum, int zNum)
  16. // constructor
  17. {
  18. this.xNum = xNum;
  19. this.yNum = yNum;
  20. this.zNum = zNum;
  21. }
  22.  
  23. public LockDataStructureClass(LockDataStructureClass lsc)
  24. //copy
  25. {
  26. this.xNum = lsc.xNum;
  27. this.yNum = lsc.yNum;
  28. this.zNum = lsc.zNum;
  29. }
  30.  
  31. public void setX(int x)
  32. {
  33. xNum = x;
  34. }
  35.  
  36. public void setY(int y)
  37. {
  38. yNum = y;
  39. }
  40.  
  41. public void setZ(int z)
  42. {
  43. zNum = z;
  44. }
  45.  
  46. public void alter(int x, int y, int z)
  47. {
  48. setX(x);
  49. setY(y);
  50. setZ(z);
  51. }
  52.  
  53. public boolean turn(int lNumber, int cNumber)
  54. //lNumber is lock number and cNumber is combination number
  55. {
  56. if(cNumber == 1)
  57. {
  58. int negate = 0;
  59.  
  60.  
  61. for(int i = 39; i >= lNumber; i--)
  62. {
  63. lid = i;
  64. System.out.print(" " + lid + " ");
  65. if(lid == lNumber)
  66. {
  67. negate++;
  68. }
  69. if(negate == 1 && lid == lNumber)
  70. {
  71. if(lid == xNum)
  72. {
  73. System.out.println("\n\n");
  74. return true;
  75. }
  76. else
  77. {
  78. return false;
  79. }
  80. }
  81. if(lid == 39)
  82. {
  83. i = -1;
  84. }
  85. }
  86. }
  87.  
  88. else if(cNumber == 2)
  89. {
  90. int negate = 0;
  91.  
  92. for(int i = lid; i <= 39; i++)
  93. {
  94. lid = i;
  95. System.out.print(" " + lid + " ");
  96.  
  97. if(lid == lNumber)
  98. {
  99. negate++;
  100. }
  101.  
  102. if(negate == 2 && lid == lNumber)
  103. {
  104. if(lid == yNum)
  105. {
  106. System.out.println("\n\n");
  107. return true;
  108. }
  109. else
  110. {
  111. return false;
  112. }
  113. }
  114. if(lid == 39)
  115. i = -1;
  116. }
  117. }
  118.  
  119. else if(cNumber == 3)
  120. {
  121. int negate = 0;
  122.  
  123. for(int i = lid; i >= 0; i--)
  124. {
  125. lid = i;
  126. System.out.print(" " + lid + "");
  127.  
  128. if(lid == lNumber)
  129. {
  130. if(lid == zNum)
  131. {
  132. System.out.println("\n\n");
  133. return true;
  134. }
  135. else
  136. {
  137. return false;
  138. }
  139. }
  140. if(lid == 0)
  141. {
  142. i = 40;
  143. }
  144. }
  145. }
  146.  
  147. else
  148. {
  149. return false;
  150. }
  151. return false;
  152. }
  153.  
  154. public void close()
  155. {
  156. sealed = true;
  157. }
  158.  
  159. public void attempt(int x, int y, int z)
  160. {
  161. boolean xExm = false;
  162. boolean yExm = false;
  163. boolean zExm = false;
  164.  
  165. xExm = turn(x, 1);
  166. System.out.println();
  167. System.out.println("\nFirst attempted lock number: " + x
  168. + "\nFirst actual lock number: " + this.xNum
  169. + "\n First lock unlock: " + xExm);
  170.  
  171.  
  172. yExm = turn(y, 2);
  173. System.out.println();
  174. System.out.println("\nSecond attempted lock number: " + y
  175. + "\nSecond actual lock number: " + this.yNum
  176. + "\n Second lock unlock: " + yExm);
  177.  
  178. zExm = turn(z, 3);
  179. System.out.println();
  180. System.out.println("\nThird attempted lock number: " + z
  181. + "\nThird actual lock number: " + this.zNum
  182. + "\n Third lock unlock: " + zExm);
  183.  
  184. if(xExm == true && yExm == true && zExm == true)
  185. {
  186. sealed = false;
  187. System.out.println("The lock is open!");
  188. }
  189. else
  190. {
  191. System.out.println("The lock is closed!");
  192. }
  193. }
  194.  
  195. public boolean inquire(boolean sealed)
  196. {
  197. if(sealed == true)
  198. {
  199. System.out.println("The lock is locked!");
  200. return true;
  201. }
  202. else
  203. {
  204. System.out.println("The lock is unlocked!");
  205. return false;
  206. }
  207. }
  208.  
  209. public int current()
  210. {
  211. return lid;
  212. }
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement