POJO, 래퍼, 그리고 java.math
모든 훌륭한 임무는 강력한 발사에서 시작됩니다! 이 연습 문제에서는 임포트되어 있는 Rocket 클래스를 발사해 볼 거예요.
이륙할 준비되셨나요?
이 연습은 강의의 일부입니다
Java의 데이터 타입과 예외
연습 안내
RocketPOJO의 인스턴스를 하나 생성하세요.- 해당 세터를 사용하여
Rocket의thrust필드를BigDecimal타입의"7770000"으로 설정하세요. .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");
}
}