import java.util.Scanner;

public class TrainTest
{
  
  public static void main(String[] args)
  {
    /**
     * Prompt the user to enter the speeds and locations of the two trains
     * Create two Trains
     * */
      Scanner scan = new Scanner(System.in);   
      double firstSpeed = 0.0, secondSpeed = 0.0, firstPosition = 0.0, secondPosition = 0.0, flySpeed = 0.0;
      
      System.out.println("Please enter the speed of the first train:");
      firstSpeed = scan.nextDouble();

      System.out.println("Please enter the position of the first train relative to the origin");
      firstPosition = scan.nextDouble();

      System.out.println();
      System.out.println("Creating the first train ...");
      Train firstTrain = new Train(firstPosition, firstSpeed);
      System.out.println();

      System.out.println("Please enter the speed of the second train:");
      secondSpeed = scan.nextDouble();

      System.out.println("Please enter the position of the second train relative to the origin");
      secondPosition = scan.nextDouble();

      System.out.println();
      System.out.println("Creating the second train ...");
      Train secondTrain = new Train(secondPosition, secondSpeed);
      System.out.println();

    /**
     * Ask the user for the fly's speed
     * */
      System.out.println();
      System.out.println("Please enter the fly's speed");
      flySpeed = scan.nextDouble();
    
    /**
     * Now using methods given in Train.java, calculate the distance travelled
     * by the fly (using the simple calculation described in the question and not 
     * an infinite sum). We assume that the trains are traveling towards each other.
     * */
      double totalTime = (firstTrain.gap(secondTrain))/(firstTrain.getSpeed() + secondTrain.getSpeed());

      double distance = flySpeed * totalTime;
    
    /**
     * Disply the resulting distance travelled by the fly to the user
     * */
      
      System.out.println();
      System.out.println("The Distance travelled by a fly travelling at the constant speed of " + flySpeed + " between two trains that are " + firstTrain.gap(secondTrain) + " apart is: " + distance);

  } 
}
