Starting from:

$30

IT210- Programming Assignment 5 Solved

This programming assignment is an expansion of P9.12 (p. 499-­‐500). Write the class Bug but assume the bug is moving on 2-­‐dimensional plane. Positions should always be expressed as a tuple of two integers (x_coord, y_coord). Your test code should exercise all parts of your code and be after

i f __name__ == "__main__":

For directions, any word beginning with N will be interpreted as North, E as East, W as West and S as South. Either case should be accepted and any other letter will be ignored. East is the direction if increasing x, north for increasing y, etc.

The following methods are expected:

d e f __init__(self, initPos = (0, 0), initDir = 'N'):

def turnRight(self):

def turnLeft(self):

def uTurn(self):

def move(self):

def moveMulti(self, count): def setPos(self, posTuple): def getPos(self):

def setDir(self, dirStr):

def getDir(self): # returns a direction string

def __repr__(self):

The string produced by __repr__ should be like this: Bug at (4, 7) facing west

Test data should use only integers for posTuple and initTuple components and for count.

More products