Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SimpleDate(private var d:Int,private var m:Int) {
- checkInputAndFix()
- private var dayInYear = (d-1 + ((m-1)*30))
- def day:Int = dayInYear%30 + 1
- def day_=(x:Int){
- if(0<x && x<31){
- dayInYear = (dayInYear%30+x)%360 + 1
- }else{
- throw new wrongDate("Wrong day!")
- }
- }
- def month:Int = dayInYear/30 + 1
- def month_=(x:Int){
- if(0<x && x<13){
- dayInYear = (dayInYear%30+x*30)%360
- }else{
- throw new wrongDate("Wrong month!")
- }
- }
- def przesun(liczbaDni:Int){
- dayInYear = (dayInYear + liczbaDni) % 360
- }
- private def checkInputAndFix(){
- if(d<1){
- d = 1
- }
- if(d>30){
- d=30
- }
- if(m<1){
- m=1
- }
- if(m>12){
- m=12
- }
- }
- }
- object SimpleDate {
- def apply(d: Int, m: Int) = new SimpleDate(d,m)
- }
- class wrongDate(message:String) extends Exception{
- print(message)
- }
- var date = new SimpleData(15,11)
- date.day
- var date2 = new SimpleData(29,12)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement