POJO, wrappers and java.math
Every great mission starts with a strong launch! In this exercise, you'll launch a Rocket class that has been imported for you.
Ready for liftoff?
Bu egzersiz
Data Types and Exceptions in Java
kursunun bir parçasıdırEgzersiz talimatları
- Create an instance of the
RocketPOJO. - Set the
Rocketthrustfield to"7770000"as aBigDecimalusing the corresponding setter. - Set the
mannedfield totrueusing the.setManned()setter.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
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");
}
}