सिम्युलेशन
आप एक हाउस व्यूइंग सिम्युलेशन बना रहे हैं। इसी उद्देश्य से, आप सिम्युलेशन में अलग-अलग ऑब्जेक्ट्स के साथ इंटरेक्ट करने के तरीके बना रहे हैं।
यह अभ्यास पाठ्यक्रम का हिस्सा है
इंटरमीडिएट Java
अभ्यास निर्देश
switchकरने के लिए अपेक्षित keyword लिखिए।- सही constant दर्ज कीजिए ताकि
"Window"और"Wall"का व्यवहार एक जैसा हो। - उचित keyword का प्रयोग करके सुनिश्चित कीजिए कि आप
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;
}
}
}