LoslegenKostenlos loslegen

Simulation

Du implementierst eine Hausbesichtigungs-Simulation. Dafür baust du Interaktionen mit verschiedenen Objekten in der Simulation ein.

Diese Übung ist Teil des Kurses

Java für Fortgeschrittene

Kurs anzeigen

Anleitung zur Übung

  • Schreibe das erwartete Schlüsselwort zum switchen.
  • Gib die richtige Konstante ein, sodass "Window" und "Wall" gleich behandelt werden.
  • Sorge dafür, dass du nicht bei default landest, indem du das passende Schlüsselwort verwendest.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

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;
    }
  }
}
Code bearbeiten und ausführen