Simulation
Vous implémentez une simulation de visite de maison. Pour cela, vous créez des interactions avec différents objets dans la simulation.
Cet exercice fait partie du cours
Java intermédiaire
Instructions
- Indiquez le mot-clé attendu pour utiliser
switch. - Saisissez la constante correcte afin que
"Window"et"Wall"aient le même comportement. - Assurez-vous de ne pas passer par
defaulten utilisant le bon mot-clé.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
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;
}
}
}