src/main/scala/space_age.scala

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
object SpaceAge {
  // Number of seconds in an Earth year
  val EarthYear = 31557600

  def apply(seconds:Long) = new SpaceAge(seconds)
}

class SpaceAge(val seconds:Long) {
  private def getYears(orbitalPeriod: Double) = {
    val years = seconds / (SpaceAge.EarthYear * orbitalPeriod)
    math.round(years * 100) / 100.0
  }

  lazy val onMercury = getYears(0.2408467)
  lazy val onVenus = getYears(0.61519726)
  lazy val onEarth = getYears(1.0)
  lazy val onMars = getYears(1.8808158)
  lazy val onJupiter = getYears(11.862615)
  lazy val onSaturn = getYears(29.447498)
  lazy val onUranus = getYears(84.016846)
  lazy val onNeptune = getYears(164.79132)
}

@abo64 thinks this looks great

Comments


You're not logged in right now. Please login via GitHub to comment