शुरू करेंमुफ़्त में शुरू करें

POJO, wrappers और java.math

हर बड़ी मिशन की शुरुआत एक मज़बूत लॉन्च से होती है! इस अभ्यास में, आप एक Rocket क्लास लॉन्च करेंगे जिसे आपके लिए पहले से इम्पोर्ट किया गया है.

लिफ्टऑफ के लिए तैयार हैं?

यह अभ्यास पाठ्यक्रम का हिस्सा है

Java में डेटा टाइप्स और Exceptions

पाठ्यक्रम देखें

अभ्यास निर्देश

  • Rocket POJO का एक इंस्टेंस बनाइए.
  • संबंधित सेटर का उपयोग करके Rocket के thrust फ़ील्ड को "7770000" के रूप में BigDecimal में सेट कीजिए.
  • .setManned() सेटर का उपयोग करके manned फ़ील्ड को true पर सेट कीजिए.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

public class Launch {

	public static void main(String[] args) {
    	// Create an instance of the Rocket POJO
		Rocket rocket = ____ ____();
		rocket.setName("Saturn");
        // Set the thrust field to as a BigDecimal
		rocket.setThrust(____ ____("7770000"));
        // Set the rocket's manned Boolean wrapper field to true
		rocket.____(____);
		fire(rocket);
	}

	public static void fire(Rocket r) {
		BigDecimal newtons = r.getThrust().divide(new BigDecimal(224));
		System.out.println("We have liftoff of: " + r.getName());
		System.out.print("Thrust is: " + newtons + " newtons of energy");
	}
}
कोड संपादित करें और चलाएँ