Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LockDataStructureClass
- {
- private int xNum;
- private int yNum;
- private int zNum;
- private int dial;
- private int lid = 0; // lid is top
- public static boolean sealed = false; // sealed is locked
- public LockDataStructureClass()
- { //default constructor
- }
- public LockDataStructureClass(int xNum, int yNum, int zNum)
- // constructor
- {
- this.xNum = xNum;
- this.yNum = yNum;
- this.zNum = zNum;
- }
- public LockDataStructureClass(LockDataStructureClass lsc)
- //copy
- {
- this.xNum = lsc.xNum;
- this.yNum = lsc.yNum;
- this.zNum = lsc.zNum;
- }
- public void setX(int x)
- {
- xNum = x;
- }
- public void setY(int y)
- {
- yNum = y;
- }
- public void setZ(int z)
- {
- zNum = z;
- }
- public void alter(int x, int y, int z)
- {
- setX(x);
- setY(y);
- setZ(z);
- }
- public boolean turn(int lNumber, int cNumber)
- //lNumber is lock number and cNumber is combination number
- {
- if(cNumber == 1)
- {
- int negate = 0;
- for(int i = 39; i >= lNumber; i--)
- {
- lid = i;
- System.out.print(" " + lid + " ");
- if(lid == lNumber)
- {
- negate++;
- }
- if(negate == 1 && lid == lNumber)
- {
- if(lid == xNum)
- {
- System.out.println("\n\n");
- return true;
- }
- else
- {
- return false;
- }
- }
- if(lid == 39)
- {
- i = -1;
- }
- }
- }
- else if(cNumber == 2)
- {
- int negate = 0;
- for(int i = lid; i <= 39; i++)
- {
- lid = i;
- System.out.print(" " + lid + " ");
- if(lid == lNumber)
- {
- negate++;
- }
- if(negate == 2 && lid == lNumber)
- {
- if(lid == yNum)
- {
- System.out.println("\n\n");
- return true;
- }
- else
- {
- return false;
- }
- }
- if(lid == 39)
- i = -1;
- }
- }
- else if(cNumber == 3)
- {
- int negate = 0;
- for(int i = lid; i >= 0; i--)
- {
- lid = i;
- System.out.print(" " + lid + "");
- if(lid == lNumber)
- {
- if(lid == zNum)
- {
- System.out.println("\n\n");
- return true;
- }
- else
- {
- return false;
- }
- }
- if(lid == 0)
- {
- i = 40;
- }
- }
- }
- else
- {
- return false;
- }
- return false;
- }
- public void close()
- {
- sealed = true;
- }
- public void attempt(int x, int y, int z)
- {
- boolean xExm = false;
- boolean yExm = false;
- boolean zExm = false;
- xExm = turn(x, 1);
- System.out.println();
- System.out.println("\nFirst attempted lock number: " + x
- + "\nFirst actual lock number: " + this.xNum
- + "\n First lock unlock: " + xExm);
- yExm = turn(y, 2);
- System.out.println();
- System.out.println("\nSecond attempted lock number: " + y
- + "\nSecond actual lock number: " + this.yNum
- + "\n Second lock unlock: " + yExm);
- zExm = turn(z, 3);
- System.out.println();
- System.out.println("\nThird attempted lock number: " + z
- + "\nThird actual lock number: " + this.zNum
- + "\n Third lock unlock: " + zExm);
- if(xExm == true && yExm == true && zExm == true)
- {
- sealed = false;
- System.out.println("The lock is open!");
- }
- else
- {
- System.out.println("The lock is closed!");
- }
- }
- public boolean inquire(boolean sealed)
- {
- if(sealed == true)
- {
- System.out.println("The lock is locked!");
- return true;
- }
- else
- {
- System.out.println("The lock is unlocked!");
- return false;
- }
- }
- public int current()
- {
- return lid;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement