开始使用免费开始使用

POJO、包装类与 java.math

每一次伟大的任务都始于稳健的发射!在本练习中,您将"发射"一个已为您导入的 Rocket 类。

准备点火起飞了吗?

本练习是课程的一部分

Java 的数据类型与异常

查看课程

练习说明

  • 创建一个 Rocket POJO 的实例。
  • 使用相应的设值器,将 Rocketthrust 字段设置为 "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");
	}
}
编辑并运行代码