def __init__(self, fileName):
     inStream = InStream(fileName)
     self._name = inStream.readLine()      # Customer name
     self._cash = inStream.readFloat()     # Cash balance
     self._stockCount = inStream.readInt() # Number of stocks
     # Stock symbols
     self._stocks = stdarray.create1D(self._stockCount, 0)
     # Share counts
     self._shares = stdarray.create1D(self._stockCount, 0)
     for i in range(self._stockCount):
         self._shares[i] = inStream.readInt()
         self._stocks[i] = inStream.readString()
Exemplo n.º 2
0
 def __init__(self, filename):
     instream = InStream(filename)
     n = instream.readInt()
     r = instream.readFloat()
     stddraw.setXscale(-r, r)
     stddraw.setYscale(-r, r)
     self._bodies = []
     for i in range(n):
         rx = instream.readFloat()
         ry = instream.readFloat()
         vx = instream.readFloat()
         vy = instream.readFloat()
         mass = instream.readFloat()
         name = instream.readString()
         r = Vector([rx, ry])
         v = Vector([vx, vy])
         b = Body(r, v, mass, name)
         print('Body created!')
         self._bodies.append(b)