# L-24 MCS 507 Mon 17 Oct 2011 : falling_object.py

# We use a class to store the paramters of a function.

class FallingObject:
   """
   Models the height of an object moving
   up at an constant velocity, subject to
   the gravitational force.
   """
   def __init__(self,v0,gc=9.81):
      """
      Stores initial velocity and
      gravitational constant.
      """
      self.v = v0
      self.g = gc

   def value(self,t):
      """
      Returns v0*t - 0.5*gc*t**2.
      """
      return self.v*t - 0.5*self.g*t**2

   def __str__(self):
      """
      Returns the formula as a string.
      """
      r = str(self.v) + '*t - 0.5*'
      r = r + str(self.g) + '*t**2'
      return r

def main():
   """
   A simple test on the class.
   """
   y = FallingObject(3)
   print 'at t = 0.1:', y.value(0.1)

if __name__=="__main__": main()
