Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A)
- package comboLock;
- public class comboLock {
- private int secret1;
- private int secret2;
- private int secret3;
- private int ticks;
- private int unlock = 0;
- public comboLock(int secret1, int secret2, int secret3)
- {
- this.secret1 = secret1;
- this.secret2 = secret2;
- this.secret3 = secret3;
- }
- public void turnLeft(int ticks)
- {
- this.ticks = ticks;
- if(ticks == secret2)
- {
- unlock++;
- }
- }
- public void turnRight(int ticks)
- {
- this.ticks = ticks;
- if(ticks == secret1)
- {
- unlock++;
- }
- if(ticks == secret3)
- {
- unlock++;
- }
- }
- public void reset()
- {
- ticks = 0;
- }
- public void open()
- {
- if (unlock == 3)
- {
- System.out.println("The lock is open");
- }
- else
- {
- System.out.println("you have enter the incorrect Combination");
- }
- }
- }
- -----------------------------------------------------------------------------------------------------------------------------------
- B)
- package comboLock;
- import java.util.Scanner;
- public class comboLockTester {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.println("Please set your combination");
- int h = in.nextInt();
- int b = in.nextInt();
- int c = in.nextInt();
- comboLock cyrus = new comboLock(h, b, c);
- System.out.println("Enter your combination");
- int v = in.nextInt();
- int e = in.nextInt();
- int r = in.nextInt();
- cyrus.turnRight(v);
- cyrus.reset();
- cyrus.turnLeft(e);
- cyrus.reset();
- cyrus.turnRight(r);
- cyrus.open();
- System.out.println(cyrus);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement