Simulare
Implementezi o simulare de vizionare a unei case. În acest scop, creezi modalități de interacțiune cu diferite obiecte din simulare.
Acest exercițiu face parte din cursul
Java intermediar
Instrucțiuni pentru exercițiu
- Scrie cuvântul cheie corect pentru instrucțiunea
switch. - Introdu constanta potrivită astfel încât
"Window"și"Wall"să aibă același comportament. - Asigură-te că execuția nu ajunge la
default, folosind cuvântul cheie corespunzător.
Exercițiu interactiv practic
Încearcă acest exercițiu completând acest cod de exemplu.
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;
}
}
}