/**
 * Inception.java
 * @author Aclan, Nelson D.
 * August 14, 2010
 *
 * Programmer's Notes:
 *    Inspired by the movie of the same title starring Leonardo DiCaprio.
 *    Hypnic jerks (http://en.wikipedia.org/wiki/Hypnic_jerk) to follow...
 */

import java.io.*;

public class Inception {
   /**
    * Dreams within a dream.
    * @param level the depth of the dream
    */
   public void dream(int level) {
      if(level <= 0) {
         return;
      }

      try {
         System.out.print("Level " + level + ": ");

         long startTime = System.currentTimeMillis();
            Thread.sleep(1000*level); //more realistic when exponential...no?
         long endTime = System.currentTimeMillis();

         System.out.println(roundOff(getElapsedTimeMin(startTime, endTime)) + " Minutes");
      } catch(InterruptedException ie) {
      }

      dream(level-1);
   }

   /**
    * Yes, you got that right; that's what this function does.
    */
   private float getElapsedTimeMin(long startTime, long endTime) {
      return (endTime-startTime)/(60*1000F);
   }

   /**
    * The following program round two decimal places of the given number.
    * http://www.roseindia.net/java/beginners/RoundTwoDecimalPlaces.shtml
    */
   private float roundOff(float elapsedTime) {
      float p, tmp;

      p = (float)Math.pow(10, 2);
      elapsedTime *= p;
      tmp = Math.round(elapsedTime);

      return (float)tmp/p;
   }

   public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      Inception i = new Inception();
      int levels;

      try {
         System.out.print("\nHow deep do you wish to dream? ");
         levels = Integer.parseInt(br.readLine().trim());
         i.dream(levels);
         System.out.println();
      } catch(NumberFormatException nfe) {
      } catch(IOException ioe) {
      }
   }
}
