IniziaInizia gratis

Simulation

You are implementing a house viewing simulation. To that end, you are creating ways to interact with different objects in the simulation.

Questo esercizio fa parte del corso

Intermediate Java

Visualizza il corso

Istruzioni dell'esercizio

  • Write down the expected keyword for switching.
  • Enter the correct constant such that "Window" and "Wall" have the same behavior.
  • Make sure you don't go through default by using the proper keyword.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

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;
    }
  }
}
Modifica ed esegui il codice