Class Planet

All Implemented Interfaces:
Comparable<CelestialBody>

public class Planet extends CelestialBody
A planet.

A planet is a CelestialBody with variable position and velocity.

  • Field Details

    • velocity

      private Point velocity
      The velocity of this planet.
  • Constructor Details

    • Planet

      public Planet(String name, int x, int y, int z)
      Constructs a planet.

      Constructs a planet initially at rest (i.e., with a velocity of zero) given its name and initial position.

      Parameters:
      name - the name.
      x - the x coordinate of the initial position.
      y - the y coordinate of the initial position.
      z - the z coordinate of the initial position.
      Throws:
      NullPointerException - if the name is null.
      IllegalArgumentException - if the name is composed of only spaces, or is empty.
  • Method Details

    • velocity

      public Point velocity()
      Description copied from class: CelestialBody
      Returns the velocity of this celestial body.
      Specified by:
      velocity in class CelestialBody
      Returns:
      the velocity (not null}).
    • updatePosition

      public void updatePosition()
      Description copied from class: CelestialBody
      Updates the position of this celestial body (usually following a change in its velocity).
      Specified by:
      updatePosition in class CelestialBody
    • updateVelocity

      public void updateVelocity(CelestialBody c)
      Description copied from class: CelestialBody
      Updates the velocity of this celestial body.

      The velocity must be updated based on the interaction with the celestial body given as an argument according to what is illustrated in the overview of this package; this method must not modify the celestial body given as an argument.

      Specified by:
      updateVelocity in class CelestialBody
      Parameters:
      c - the celestial body to interact with.
    • toString

      public String toString()
      Overrides:
      toString in class Object