对于我的程序,我想模拟一个密码锁。所以我要求用户将组合锁更改为一个新的3位数组合,但我不知道我哪里出错它似乎留在(0,0,0)
public class Lock
{
private int xCombo;
private int yCombo;
private int zCombo;
private int top = 0;
public static boolean locked = false;
public Lock()
{
xCombo = 0;
yCombo = 0;
zCombo = 0;
}
public void alter(int x, int y, int z)
{
xCombo = x;
yCombo = y;
zCombo = z;
从我的演示课
public class LockDemo
{
public static void main(String [] arg)
{
lockMenu();
}
public static void lockMenu()
{
int x, y, z;
Scanner kb = new Scanner(System.in);
Lock newLock = new Lock();
System.out.println("\nSelect an option for the lock.\n");
System.out.println(" A : Set a new lock combination. ");
System.out.println(" B : Close the lock.");
System.out.println(" C : Attempt to open the lock.");
System.out.println(" D : Check lock status.");
System.out.println(" E : Check current top number.");
char menuOption = kb.next().charAt(0);
menuOption = Character.toUpperCase(menuOption);
switch(menuOption)
{
case 'A':
{
System.out.println("Set a new combination for the lock.\n");
System.out.println("Enter the first number of the combination.");
x = kb.nextInt();
System.out.println("Enter the second number of the combination.");
y = kb.nextInt();
System.out.println("Enter the third number of the combination.");
z = kb.nextInt();
newLock.alter(x,y,z);
lockMenu();
感谢您的帮助,如果我需要发布更多我将编辑的代码