2014-10-21 2 views
-1

라인 public static String guessColor (스캐너 키보드)은 내 오류가있는 곳입니다. 오류는 다음과 같습니다. 불법적 인 표현식 시작 : public 및 static. 오류 : ';' 예상 : 문자열과 guessColor 사이. 오류 ';' 예상 : 스캐너와 키보드 사이. 불법적 인 표현의 시작 : at).내 ESP 게임 메소드에서 불법적 인 표현식 시작

public class RichardsonESPGame 
{     
public static void main(String[] args) 
    { 
    String random; 
    String guess;   
    Scanner keyboard = new Scanner(System.in);   

    random = computerColor(); 
    guess = guessColor(keyboard);   
    String end = recordGame(random, guess); 
    System.out.println(end); 

    keyboard.close(); 
    } 
/** 
In this method the color choices will be displayed. 
*/   
public static String computerColor() 
    {  
    Random rand = new Random(); 
    int color = rand.nextInt(5) + 1; 
    return receiveColor(color); 
    }  


/** 
This method will give the computer and user its color options. 
*/ 
public static String receiveColor(int color) 
{ 
    String selection; 
    switch (color) 
    { 
     case 1: 
     selection = "Red"; 
     break; 
     case 2: 
     selection = "Blue"; 
     break; 
     case 3: 
     selection = "Green"; 
     break; 
     case 4: 
     selection = "Yellow"; 
     break; 
     case 5: 
     selection = "Orange"; 
     break; 
     default: 
     System.out.println("Make a valid selection."); 
     selection = null; 
    } 
    return selection; 

/** 
This method will get the user's color choice. 
*/ 
public static String guessColor(Scanner keyboard) 
    { 
    System.out.println("Enter a number from 1 to 5 to receive a color.\n 1 is Red\n 2 is Blue\n 3 is Green\n 4 is Yellow\n 5 is Orange\n"); 
    int richardsonGuessColor = keyboard.nextInt(); 
    String color = receiveColor(richardsonGuessColor); 

    while (color == null) 
    { 
     System.out.println("Enter a number from 1 to 5 to receive a color.\n 1 is Red\n 2 is Blue\n 3 is Green\n 4 is Yellow\n 5 is Orange\n"); 
     int guess = keyboard.nextInt(); 
     color = receiveColor(richardsonGuessColor); 
    } 

    return color;   
    } 

/** 
This method will determine if user guesses correctly. 
*/ 

public static String recordGame(String richardsonComputerColor, String richardsonGuessColor) 
    { 

    String end; 
    end = "The computer's choice was: " + richardsonComputerColor; 
    end += "Your choice was: " + richardsonGuessColor; 

     if(richardsonGuessColor.equalsIgnoreCase("Red")) 
     { 
       if (richardsonComputerColor.equalsIgnoreCase("Red")) 
       { 
       end += "You guessed correctly!"; 
       }  
       else 
       { 
       result += "You guessed incorrectly."; 
       } 
     } 

     else if(richardsonGuessColor.equalsIgnoreCase("Blue")) 
      { 
        if (richardsonComputerColor.equalsIgnoreCase("Blue")) 
       { 
        end += "You guessed correctly!"; 
       }  
       else 
       { 
        result += "You guessed incorrectly."; 
       } 
      } 

     else if(richardsonGuessColor.equalsIgnoreCase("Green")) 
      { 
        if (richardsonComputerColor.equalsIgnoreCase("Green")) 
       { 
        end += "You guessed correctly!"; 
       }  
       else 
       { 
        result += "You guessed incorrectly."; 
       } 
      } 
    else if(richardsonGuessColor.equalsIgnoreCase("Yellow")) 
      { 
        if (richardsonComputerColor.equalsIgnoreCase("Yellow")) 
       { 
        end += "You guessed correctly!"; 
       }  
       else 
       { 
        result += "You guessed incorrectly."; 
       } 
     } 
    else if(richardsonGuessColor.equalsIgnoreCase("Orange")) 
      { 
        if (richardsonComputerColor.equalsIgnoreCase("Orange")) 
       { 
        end += "You guessed correctly!"; 
       }  
       else 
       { 
        result += "You guessed incorrectly."; 
       } 
      }  
    return end; 
    } 

} 

답변

0

이전 방법으로는 최종 닫는 대괄호를 사용하지 않았기 때문에 이러한 현상이 발생합니다. 이 문제를 해결하려면 recieveColor 메서드의 return 문 다음에 닫기 대괄호를 추가하면됩니다.

관련 문제