Facebook
From Mammoth Stork, 1 Year ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 252
  1. object HelloWorld {
  2.    def main(args: Array[String]) {
  3.       println(DateInYear(100,200))
  4.    }
  5.    
  6.    class DateInYear(private var d: Int, private var m: Int) {
  7.         if (d < 1) d = 1
  8.         if (d > 30) d = 30
  9.         if (m < 1) m = 1
  10.         if (m > 12) m = 12
  11.        
  12.         def day: Int = d
  13.         def month: Int = m
  14.  
  15.         def day_=(newDay: Int) {
  16.             if (newDay < 1) d = 1
  17.             if (newDay > 30) d = 30
  18.             else d = newDay
  19.         }
  20.        
  21.         def month_=(newMonth: Int) {
  22.             if (newMonth < 1) m = 1
  23.             if (newMonth > 12) m = 12
  24.             else m = newMonth
  25.         }
  26.        
  27.         override def toString = d + "." + m
  28.     }
  29.    
  30.     object DateInYear {
  31.         def apply(day: Int, month: Int) = new DateInYear(day, month)
  32.     }
  33. }