object LunarLander {

  def main(args: Array[String]): Unit = {}

  val lunarG = 1.6249    // meters/(second * second), accel. of gravity
  val fuelConstant = 0.1 // adjusts how burning fuel affects velocity
  var playAgain = true

  println("Welcome to Lunar Lander! And good luck!")
  while (playAgain) {
    var seconds = 0.00
    
    var altitude = 5000.0 // meters (initially 20 km)
    var velocity = 500.0  // meters per second
    var fuel = 7500.0     // kg
    while (altitude > 0) {
      println
      println(s"After $seconds seconds,")
      println(s"Your altitude is $altitude meters.")
      println(s"Your velocity is $velocity meters/second.")
      println(s"You have $fuel liters of fuel remaining.")
      seconds = seconds + 10
      var burn = if (fuel > 0) {
        Math.min(fuel, augmentString(readLine("How much fuel will you burn? ")).toDouble)
      } else 0
      velocity = velocity + 10 * lunarG
      velocity = velocity - fuelConstant * burn
      altitude = altitude - velocity
      fuel = fuel - burn
    }
    println
    println(s"Velocity at impact is $velocity meters/second.")
    if (velocity < 5) {
      println("Perfect landing! Congratulations!")
    } else if (velocity < 10) {
      println("Congratulations on a good landing (could be better)")
    } else if (velocity < 20) {
      println("CRASH!")
      println("Your module is severely damaged, and you are")
      println("stranded on the moon! Hope you have lots of oxygen!")
    } else {
      println("CRASH!")
      println("You have crashed on the moon. There are no survivors.")
      println("In addition, you have just blasted a new crater ")
      println(s"${velocity * velocity / 1000} meters deep!")
    }
    val answer = readLine("Would you like to play again? ")
    playAgain = answer.startsWith("y") || answer.startsWith("Y")
  }
  println("Goodbye!")
}