1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
namespace TimedObjects {
     using System;
     public class Pendulum {
          private DateTime timeStamp;
          private TimeSpan span;
          private bool position1;
          private bool position2;
          private bool failedState;

          public Pendulum(int spanValue){
               this.position1 = true;
               this.position2 = false;
               this.timeStamp = new DateTime(DateTime.Now.Ticks);
	              this.span = new TimeSpan(spanValue * TimeSpan.TicksPerSecond);
               this.failedState = false;
          }

         public DateTime getTimeStamp() {
              return this.timeStamp;
         }
         public bool isInFailedState() {
              return this.failedState;
         }
         public void tick() {
              DateTime rightNow = new DateTime(DateTime.Now.Ticks);
              TimeSpan diffR = (rightNow - this.timeStamp);
              
              if (diffR.TotalSeconds > this.span.TotalSeconds)
              {
                   this.failedState = true;
              }
              else
              {
                   if (this.position1) {
                        this.position1 = false;
                        this.position2 = true;
                   } else if(this.position2) {
                        this.position1 = true;
                        this.position2 = false;
                   }
                   this.timeStamp = rightNow;
              }
         }
     }
}