Get startedGet started for free

POJO, wrappers and java.math

Every great mission starts with a strong launch! In this exercise, you'll define a Rocket class and write the code to launch it. Ready for liftoff?

This exercise is part of the course

Data Types and Exceptions in Java

View Course

Exercise instructions

  • Create an instance of the Rocket POJO.
  • Set the Rocket thrust field to "7770000" as a BigDecimal using the corresponding setter.
  • Set the Boolean wrapper manned field to true using the corresponding setter.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

import java.math.BigDecimal;

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");
	}
}

public class Rocket {

	private String name;
	private BigDecimal thrust;
	private Boolean manned;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public BigDecimal getThrust() {
		return thrust;
	}
	public void setThrust(BigDecimal thrust) {
		this.thrust = thrust;
	}
	public Boolean isManned() {
		return manned;
	}
	public void setManned(Boolean manned) {
		this.manned = manned;
	}
}
Edit and Run Code