package hw09 // Compile with: scalac calendar.scala // Run with: scala hw09.calendar object calendar { /***************************************************************************** * Warm-Up */ // def unlines(lines: ...): ... = ... /***************************************************************************** * Calendars */ /** * The weekday of January 1st in year y, represented * as an Int. 0 is Sunday, 1 is Monday etc. */ def firstOfJan(y: Int): Int = { val x = y - 1 (365*x + x/4 - x/100 + x/400 + 1) % 7 } def isLeapYear(y: Int) = if (y % 100 == 0) (y % 400 == 0) else (y % 4 == 0) def mlengths(y: Int): List[Int] = { val feb = if (isLeapYear(y)) 29 else 28 List(31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) } // def firstDay(m: Int, y: Int): Int = ... case class Picture(height: Int, width: Int, pxx: List[List[Char]]) { // def showIt: String = unlines(pxx).mkString // def above(q: Picture) = ... // def beside(q: Picture) = ... } def pixel(c: Char) = Picture(1, 1, List(List(c))) // def stack(pics: List[Picture]): Picture = ... // def spread(pics: List[Picture]): Picture = ... // def tile(pxx: List[List[Picture]]): Picture = ... // def rightJustify(w: Int)(chars: List[Char]): Picture = ... // def group[T](n: Int, xs: List[T]): List[List[T]] = ... // def dayPics(d: Int, s: Int): List[Picture] = ... // def calendar(year: Int, month: Int): Picture = ... /***************************************************************************** * Main method for your tests */ def main(args: Array[String]) { println("2012 is leap year: "+ isLeapYear(2012)) } }