Question: public class Asgn02_ComboLock { public static Scanner cin = new Scanner(System.in); private static int cmdCount = 0; public static void main(String[] args) { int secret1,

public class Asgn02_ComboLock {

public static Scanner cin = new Scanner(System.in);

private static int cmdCount = 0;

public static void main(String[] args) {

int secret1, secret2, secret3;

out.println("CPS 151 Assignment 2 (ComboLock) by Your name here");

out.print("Enter 3 integers in range [0, 39] to create the lock: ");

secret1 = cin.nextInt();

secret2 = cin.nextInt();

secret3 = cin.nextInt();

ComboLock L = new ComboLock(secret1, secret2, secret3);

char choice = showMenuGetChoice();

// process user's choice in a loop

while (choice != 'Q') {

applyChoice(choice, L);

choice = showMenuGetChoice();

} // end loop

out.println(" Goodbye");

} // end main

private static void applyChoice(char choice, ComboLock L) {

// Write the code

} // end method

static void displayMenu() {

out.println(" Your choices: turnLeft, turnRight, Open, Begin again, Quit");

cmdCount++;

out.print(cmdCount + ". Your choice (L/R/O/B/Q): ");

} // end displayMenu

private static char showMenuGetChoice() {

displayMenu();

return cin.next().toUpperCase().charAt(0);

} // end method

private static void turnLeft(ComboLock L) {

// Write the code

} // end method

private static void turnRight(ComboLock L) {

// Write the code

} // end method

private static void open(ComboLock L) {

// Write the code

} // end method

private static int getInt(String prompt) {

out.print(prompt);

return cin.nextInt();

} // end method

} // end client class

// --------------------- class ComboLock

class ComboLock {

// possible states for a ComboLock

private static final int START = 1, FIRST = 2, SECOND = 3, THIRD = 4,

OPEN = 5, DEAD = 6;

private static final String[] STATE_NAMES = {"", "START", "FIRST", "SECOND",

"THIRD", "OPEN", "DEAD"};

private int currentState;

private final int SECRET1, SECRET2, SECRET3;

public ComboLock(int secret1, int secret2, int secret3) {

// Write the code

} // end constructor

private void showState() {

out.println("The Lock state is " + STATE_NAMES[currentState]);

} // end method

public void reset() {

// Write the code

} // end reset

public void turnLeft(int ticks) {

// Write the code

// turnLeft is only valid at state FIRST

} // end turnLeft

public void turnRight(int ticks) {

// Write the code

// turn right is valid at state START or state SECOND

} // end turnLeft

public boolean open() {

// Write the code

// Change from THIRD, stay OPEN if already open

// otherwise move to DEAD

} // end open

// add any other private methods you may want

} // end class ComboLock public class Asgn02_ComboLock { public static Scanner cin = new Scanner(System.in); private

static int cmdCount = 0; public static void main(String[] args) { intsecret1, secret2, secret3; out.println("CPS 151 Assignment 2 (ComboLock) by Your name here");

Enter 3 integera in range [O, ?9] to create the lock; 20 20 30 1. Your choice (L/R/O/B/o): r Enter number of ticka to turn [1,391:30 Your choices: turnleft, turnkight, Open, Begin again, ouit Enter number of ticks to turn [1,391 10 Your choices: turnLeft, curnRight, Open, Begin again. Quit Enter nusber of tieka to curn [.39: 30 Your choices: turnLeft, turnRight, Open, Begin again, Quit Your choices: turntett, turnRight, Open, Begin again, Ouit Your choices: turnteft, turnRight, Open, Begin again, Ouit Enter number of ticks to turn [i, 3911 20 Your choices: turnLe:?, tunkigtt, 0pen, Begin agsa, Ouit scratch Your choicea: turnLeft, turnRight, Open, Begin again, Quit Enter nusber of tieks to curn [,39: 30 Your choices: turnLeft, turnRight, Open, Begin again, Quit 10. Your choice (L/R/O/B/ON11 Enter number of ticka to curn [1.391: 10 Your choices turnteft, turnRight, Open, Begin again, Ouit scratch Your choicea: turnLeft, turnRight, Open, Begin again, Qust BUILD SUCCESSFUL [total time: 2 ?1nutes 5 5econds)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!