public class Train
{
  /*******************************************************
    *                       Attributes
    *******************************************************/
  // The train's starting position (relative to the origin)
  private double startPosition;
  
  // The train's constant speed
  private double speed;
  
  /********************************************************
    *                        Methods
    *******************************************************/
  
  // Constructor  
  public Train(double somePos, double someSpeed)
  {
      startPosition = somePos;
      speed = someSpeed;    
  }
  
  /***************************
    *     Accessor Methods
    ***************************/
  
  /**
   * Pre: None
   * Post: Returns the value of the train's startPos
   * */
  public double getPosition()
  {
      return startPosition;
  }
  
  /**
   * Pre: None
   * Post: Returns the value of the train's speed
   * */
  public double getSpeed()
  {
      return speed;
  }
  
  /**
   * Pre: None
   * Post: Updates the train's startPos to a new value
   * */
  public void setPosition(double newPos)
  {
      startPosition = newPos;
  }
  
  /**
   * Pre: None
   * Post: Updates the train's speed to a new value
   * */
  public void setSpeed(double newSpeed)
  {
      speed = newSpeed;
  }
  
  /**
   * Pre: None
   * Post: Given a second train, computes the gap between the current train and the 
   * (given) second train.
   * */
  public double gap(Train secondTrain)
  {
      // Positions are relative to the origin and to get the gap between the two trains, we merely add their (non-negative) distances relative to the origin
      double gapBetween = Math.abs(secondTrain.getPosition()) + Math.abs(startPosition); 
      return gapBetween;
  }
 
}
