karol_dziachan

test class scala

Jan 8th, 2021
1,022
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Time(private var actualHour: Int = 0, private var actualMinute: Int = 0, private var actualSecond: Int = 0){
  2.   if(actualHour < 0) actualHour = 0
  3.   if(actualMinute < 0) actualMinute = 0
  4.   if(actualSecond < 0) actualSecond = 0
  5.  
  6.   println(s"time constructor: $this")
  7.  
  8.   def hour: Int = actualHour
  9.   def hour_=(newHour:Int)
  10.   {
  11.     if(newHour < 0 || newHour > 60) throw  new IllegalArgumentException("Bad arg")
  12.     else actualHour = newHour
  13.   }
  14.  
  15.   def minute: Int = actualMinute
  16.   def minute_=(newMinute: Int)
  17.   {
  18.     if(newMinute  < 0 || newMinute > 60) throw new IllegalArgumentException("Bad arg")
  19.     else actualMinute = newMinute
  20.   }
  21.  
  22.   def second: Int = actualSecond
  23.   def second_=(newSecond:Int)
  24.   {
  25.     if(actualSecond < 0 || actualSecond > 60) throw new IllegalArgumentException("Bad arg")
  26.     else actualSecond = newSecond
  27.   }
  28.  
  29.   def before(time:Time):Boolean={
  30.     this.actualHour < time.actualHour || this.actualHour == time.actualHour && this.actualMinute < time.actualMinute || this.actualHour == time.actualHour && this.actualMinute == time.actualMinute && this.actualSecond < time.actualSecond
  31.   }
  32.  
  33.   def secondAfterMidnight:Int={
  34.     actualSecond+actualMinute*60+actualHour*60*60
  35.   }
  36.  
  37.   override def toString : String = s"$actualHour:$actualMinute:$actualSecond"
  38. }
  39.  
  40.  
  41.  
  42. object Tester{
  43.   def main(args: Array[String]) : Unit={
  44.     var time = new Time
  45.     var time1 = new Time(1)
  46.     var time2 = new Time(1,29)
  47.     var time3 = new Time(1,24,30)
  48.     var time4 = new Time(0,  50, 12 )
  49.     var time5 = new Time(1,  24, 18)
  50.     var time6 = new Time(1,  24, 30)
  51.  
  52.     println(time )
  53.     println(time1)
  54.     println(time2)
  55.     println(time3)
  56.     println(time4)
  57.     println(time5)
  58.     println(time6)
  59.  
  60.  
  61.    println(time.before(time1))
  62.    println(time.before(time2))
  63.    println(time.before(time3))
  64.    println(time1.before(time4))
  65.    println(time1.before(time5))
  66.    println(time1.before(time6))
  67.    println(time2.before(time3))
  68.  
  69.     println(time.secondAfterMidnight)
  70.    println(time1.secondAfterMidnight)
  71.    println(time6.secondAfterMidnight)
  72.    println(time5.secondAfterMidnight)
  73.    println(time4.secondAfterMidnight)
  74.  
  75.     println(time3)
  76.     time3.hour_=(3)
  77.     time3.minute_=(34)
  78.     time3.second_=(27)
  79.     println(time3)
  80.  
  81.   }
  82. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×