ComenzarEmpieza gratis

POJO, wrappers y java.math

¡Toda gran misión empieza con un buen lanzamiento! En este ejercicio, vas a lanzar una clase Rocket que ya ha sido importada para ti.

¿Listo para el despegue?

Este ejercicio forma parte del curso

Tipos de datos y excepciones en Java

Ver curso

Instrucciones del ejercicio

  • Crea una instancia del POJO Rocket.
  • Establece el campo thrust de Rocket a "7770000" como un BigDecimal usando su setter correspondiente.
  • Establece el campo manned en true usando el setter .setManned().

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

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");
	}
}
Editar y ejecutar código