Can';t找出这些编译器错误(Java)

Can';t找出这些编译器错误(Java),java,syntax,Java,Syntax,这是我的全部密码。我遇到了java语法错误、重复的方法,但我似乎无法理解其中的大部分。感谢您的帮助。这是一个用来模拟操纵锁的程序 此外,第一次在这里张贴海报,所以如果您需要我的任何其他信息,请让我知道。谢谢 编辑:在底部添加错误。另外,我使用DrJava.jar作为我的程序来实现这一点 EDIT2:更新的修订代码和当前错误 import java.util.Scanner; public class Lock{ private static int first; private static

这是我的全部密码。我遇到了java语法错误、重复的方法,但我似乎无法理解其中的大部分。感谢您的帮助。这是一个用来模拟操纵锁的程序

此外,第一次在这里张贴海报,所以如果您需要我的任何其他信息,请让我知道。谢谢

编辑:在底部添加错误。另外,我使用DrJava.jar作为我的程序来实现这一点

EDIT2:更新的修订代码和当前错误

import java.util.Scanner;

public class Lock{
private static int first;
private static int second;
private static int third;
private Boolean isClosed;
// private static int[] dial = new int[40];           NO LONGER IMPLEMENTING ARRAY
private static int activeNumber = 0;
public int revoCount = 0;
public int count;
public int tempFirst;
public int tempSecond;
public int tempThird;
private Boolean isClockwise;
private int desiredNumber;

Scanner in = new Scanner(System.in);

/**for (int i = 0; i < 40; i++)
{                                                     NO LONGER IMPLEMENTING ARRAY
  dial[i] = i;
} **/

//*****************************************************************************************************

public Lock()
{ 
  first = 1;
  second = 2;
  third = 3; 
}

//*****************************************************************************************************

public void alterCombo(int x, int y, int z)
{ 
  first = x;
  second = y;
  third = z;
  System.out.println("The correct combination needed has been changed to: " + first +     ", " + second + ", " + third);
  return; 
}

    //*****************************************************************************************************

public void turnLock()
{       
  System.out.print("This is a lock that goes from 0 to 39. You must turn the knob clockwise first, then counterclockwise twice, ");
  System.out.print("then clockwise for the final input. Specify how many revolutions you want (Positive number indicates ");
  System.out.println("COUNTER CLOCKWISE. Negative number indicates CLOCKWISE.");

  turnFirstNumber();
  turnSecondNumber();
  turnThirdNumber();

    System.out.println("The combination you chose was: " + tempFirst + ", " +     tempSecond + ", and " + tempThird + ".");
  return;
}
    //*****************************************************************************************************

public void closeLock()
{ 
  if (isClosed)
    System.out.println("Lock is already closed.");
  else
  {
    System.out.println("Lock has been closed.");
    isClosed = true;
  }
  return; 
}

//*****************************************************************************************************

public void openLock()
{ 
  if ((turnFirstNumber()) && (turnSecondNumber()) && (turnThirdNumber()) && (isClosed)) //if all 3 passed and lock is not open already
  { 
    isClosed = false;
    System.out.println("Your combination is correct and the lock has been opened.");
    return; 
  }
  else if (!isClosed)                                                        //lock's already open
  { 
    System.out.println("The lock is already open.");
    return;
  }
  else if ((!turnFirstNumber()) && (turnSecondNumber()) && (turnThirdNumber())) //first wrong
  {
    System.out.println("The first number you input is incorrect.");
    return;
  }
  else if ((!turnFirstNumber()) && (!turnSecondNumber()) && (turnThirdNumber())) //first and second wrong
  {
    System.out.println("The first 2 numbers you input are incorrect.");
    return;
  }
  else if ((!turnFirstNumber()) && (turnSecondNumber()) && (!turnThirdNumber())) //first and third wrong
  {
    System.out.println("The first and last numbers you input are incorrect.");
    return;
  }
  else if ((turnFirstNumber()) && (turnSecondNumber()) && (!turnThirdNumber())) //third wrong
  {
    System.out.println("The last number you input is incorrect.");
    return;
  }
  else if ((turnFirstNumber()) && (!turnSecondNumber()) && (!turnThirdNumber())) //second and third wrong
  {
    System.out.println("The second and last numbers you input are incorrect.");
    return;
  }
  else if ((turnFirstNumber()) && (!turnSecondNumber()) && (turnThirdNumber())) //second is wrong
  {
    System.out.println("The second number you input is incorrect.");
    return;
  }
  else
  { 
    System.out.println("Your entire combination is INCORRECT. Please try again."); //all wrong
    return; 
  }
}

  //*****************************************************************************************************

public void lockStatus()   
{
  if (isClosed)
  { 
    System.out.println("Closed");
    return;
  }
  else
  { 
    System.out.println("Open");
    return;
  }
}
 //*****************************************************************************************************

public static int getActiveNumber()
{
  return activeNumber;
}

//*****************************************************************************************************

private boolean turnFirstNumber()
{
  System.out.print("What is your desired direction and number of revolutions? (Positive number is counterclockwise, negative number is clockwise): ");
  count = in.nextInt();
  if (count > 0)
    isClockwise = false;
  else if (count < 0)
    isClockwise = true;
  else
  {
    throw new InvalidInputException("Your desired direction of spinning the lock is invalid. Please choose a number other than 0.");
    return false;
  }
  System.out.print("\nWhat is your desired first number?: ");
  desiredNumber = in.nextInt();

  if (!isClockwise) //user desires countercockwise revolution
  {
    do {
      for (int i = 0; i < (count * 40); i++)
      {
        activeNumber++;
          if (activeNumber > 39)
            activeNumber = 0;
          if (activeNumber == desiredNumber)
            revoCount++;
      }
       } while ((activeNumber != desiredNumber) && (revoCount < count));
  }      
  else if (isClockwise) //user desires clockwise revolution
  {
    do {
      for (int i = 0; i < (Math.abs(count) * 40); i++)
      {
      activeNumber--;
        if (activeNumber < 0)
          activeNumber = 39;
        if (activeNumber == desiredNumber)
          revoCount++;
      }
       } while ((activeNumber != desiredNumber) && (revoCount < Math.abs(count)));
  }

  tempFirst = activeNumber;

  if ((activeNumber == first) && (count < 0)) //if first number is correct and user picked correct orientation and revolutions
    return true;
  else
    return false;
  revoCount = 0;
}

//*****************************************************************************************************

private boolean turnSecondNumber()
{
  System.out.print("What is your desired direction and number of revolutions? (Positive number is counterclockwise, negative number is clockwise): ");
  count = in.nextInt();
  if (count > 0)
    isClockwise = false;
  else if (count < 0)
    isClockwise = true;
  else
  {
    throw new InvalidInputException("Your desired direction of spinning the lock is invalid. Please choose a number other than 0.");
    return false;
  }
  System.out.print("\nWhat is your desired second number?: ");
  desiredNumber = in.nextInt();

  if (!isClockwise) //user desires countercockwise revolution
  {
    do {
      for (int i = 0; i < (count * 40); i++)
      {
        activeNumber++;
          if (activeNumber > 39)
            activeNumber = 0;
          if (activeNumber == desiredNumber)
            revoCount++;
      }
       } while ((activeNumber != desiredNumber) && (revoCount < count));
  }      
  else if (isClockwise) //user desires clockwise revolution
  {
    do {
      for (int i = 0; i < (Math.abs(count) * 40); i++)
      {
      activeNumber--;
        if (activeNumber < 0)
          activeNumber = 39;
        if (activeNumber == desiredNumber)
          revoCount++;
      }
       } while ((activeNumber != desiredNumber) && (revoCount < Math.abs(count)));
  }

  tempSecond = activeNumber;

  if ((activeNumber == second) && ((count == "+2") || (count == "2"))) //if second number is correct and user picked correct orientation and revolutions
    return true;
  else
    return false;
  revoCount = 0;
}

//*****************************************************************************************************

private boolean turnThirdNumber()
{
  System.out.print("Enter '1' to twist the dial counterclockwise until you reach your desired number. Enter '-1' to twist the dial clockwise until you reach your desired number.: ");
  count = in.nextInt();
  if ((count == "1") || (count == "+1"))
    isClockwise = false;
  else if (count == "-1")
    isClockwise = true;
  else
  {
    throw new OutOfBoundsException("You are not supposed to do a full revolution on the third number of the combination. Now you have to restart.");
    return false;
  }
  System.out.print("\nWhat is your desired third and final number?: ");
  activeNumber = in.nextInt();
  activeNumber = Math.abs(activeNumber);
  tempThird = activeNumber;
  /** if (!isClockwise) //user desires countercockwise revolution
  {
    do {
        activeNumber++;
          if (activeNumber > 39)
            activeNumber = 0;
       } while (activeNumber != desiredNumber)
  } 
  else if (isClockwise) //user desires clockwise revolution
  {
    do {
      for (int i = 0; i < (count * 40); i++)
      {
      activeNumber--;
        if (activeNumber < 0)
          activeNumber = 39;
       } while (activeNumber != desiredNumber)
  }                                                                           REDUNDANT. Same result, more work.*/
  if (activeNumber > 39)
  {
    throw new OutOfBoundsException("You desire a number that is not on the lock. The lock goes from 0 to 39. Try again.");
    return false;
  }
  if ((activeNumber == third) && (isClockwise)) //if third number is correct and user picked correct orientation and revolutions
    return true;
  else    
    return false;
}

//*****************************************************************************************************
}

查看编译错误中显示的信息。比如说

turnLock
中的这些变量声明应该在类块中

public boolean isClockwise = false;
public int tempFirst = 0;
public int tempSecond = 0;
public int tempThird = 0;
public int desiredNumber = 0;
public int count = 0;
revoCount
从未声明

private int revoCount;
您的
do-while
语句中缺少许多分号

} while ((activeNumber != desiredNumber) && (revoCount < Math.abs(count)));
                                            add this ---------------------^

通常,您必须返回布尔值(true或false),因为您将方法的返回值声明为boolean,但您没有,所以将其更改为void

将其添加到类块:

public int revoCount;
更改第266行及以下内容。致:

if (count == 1)  //there is no difference between int with the value 1 and +1
isClockwise = false;
最后:删除最后一个返回:类定义不以返回结束


这将删除大多数错误,但您应该看看如何在Java中定义类。

转到控制台,复制并粘贴错误。添加的错误将显示在操作的底部。谢谢谢谢谢谢,我忘记删除最后一个返回;在从文件中删除“Main”之后,谢谢,几年后重新使用Java并忘记了这一点。在编辑和当前错误后使用当前代码更新OP
if (count == 1)  //there is no difference between int with the value 1 and +1
isClockwise = false;