시작하기무료로 시작하기

시뮬레이션

집 내부를 둘러보는 시뮬레이션을 구현하고 있어요. 이를 위해 시뮬레이션에서 다양한 객체와 상호작용하는 방법을 만들고자 합니다.

이 연습은 강의의 일부입니다

중급 Java

강의 보기

연습 안내

  • switch에 필요한 키워드를 작성하세요.
  • "Window""Wall"이 동일하게 동작하도록 올바른 상수를 입력하세요.
  • 적절한 키워드를 사용해 default로 가지 않도록 하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

class Interactor {
  public static void main(String[] args) {
    String object = "Wall";

    // Write down the correct keyword to allow for case switching
    ____ (object) {
      case "Door":
        System.out.println("You have discovered a new room");
        break;
      case "Fridge":
        System.out.println("The food is all yours");
        break;
      // Enter the correct constant to give the same behavior to Window and Wall
      case "____":
      case "Window":
        System.out.println("I can't go through that");
        // Make sure you don't go through the default case by using the correct keyword
        ____;
      default:
        System.out.println("This object cannot be interacted with");
        break;
    }
  }
}
코드 편집 및 실행