2013-09-21 3 views
0

이 코드를 작동 시키려면 어떻게해야합니까? 3 가지 시나리오의 진술을 반환해야합니다. 현재 String robotInfo에서 오류가 발생합니다.Return 문

String generateStatusReport(Robot robot) { 

    String robotStatus; 
    String robotWall; 
    String robotGround; 
    String robotInfo = robotStatus + robotWall + robotGround; 

    if(isRobotDead(robot)) { 
     robotStatus = ("The robot is dead."); 
    } else { 
     robotStatus = ("The robot is alive."); 
     if(isRobotFacingWall(robot)) { 
      robotWall = ("The robot is facing a wall."); 
     } else { 
      robotWall = ("The robot is not facing a wall."); 
     } 

     if(isItemOnGroundAtRobot(robot)) { 
      robotGround = ("There is an item here."); 
     } else { 
      robotGround = ("There is no item here."); 
     } 
    } 
    return robotInfo; 
} 

답변

0

당신은 robotInfo

String robotStatus; 
    String robotWall; 
    String robotGround; 
1

내가 조건 이후에 연결을 이동할 것을 값을 얻을 수 있도록 문자열을 초기화 할 필요가 있지만, return 문 앞에 :

String generateStatusReport(Robot robot) { 

    String robotStatus; 
    String robotWall; 
    String robotGround; 

    if(isRobotDead(robot)) 
     robotStatus = ("The robot is dead."); 
    else { 
     robotStatus = ("The robot is alive."); 
     if(isRobotFacingWall(robot)) 
      robotWall = ("The robot is facing a wall."); 
     else 
      robotWall = ("The robot is not facing a wall."); 

     if(isItemOnGroundAtRobot(robot)) 
      robotGround = ("There is an item here."); 
     else 
      robotGround = ("There is no item here."); 
    } 
    String robotInfo = robotStatus + robotWall + robotGround; 
    return robotInfo; 
} 

하거나 연결을 반환하십시오.

return robotStatus + robotWall + robotGround;