LoslegenKostenlos loslegen

POJO, Wrapper und java.math

Jede große Mission beginnt mit einem starken Start! In dieser Übung startest du eine Rocket-Klasse, die bereits für dich importiert wurde.

Bereit zum Abheben?

Diese Übung ist Teil des Kurses

Datentypen und Exceptions in Java

Kurs anzeigen

Anleitung zur Übung

  • Erstelle eine Instanz des Rocket-POJO.
  • Setze das Feld thrust von Rocket auf "7770000" als BigDecimal mithilfe des passenden Setters.
  • Setze das Feld manned mit dem Setter .setManned() auf true.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

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");
	}
}
Code bearbeiten und ausführen