Faculty of Information Technology Department of Software Engineering Assignment4

advertisement
Faculty of Information Technology
Department of Software Engineering
Assignment4
Lecturer
Module
: Dr. Ali Fouad
: Advanced Object Oriented Programming
Problem:
(a) Write a Point class that represents the points in a two-dimensional space. Your Point class
will have two instance variables x and y to indicate the x-coordinate and y-coordinate locations.
In Point class, you have to declare the following methods:
 The constructor of Point class can be invoked with no-arguments or with twoarguments.
 The instance method move moves the current Point object in the two-dimensional
space. It takes two double values as parameters: the first one is the moving distance in
x-coordinate; the second one is the moving distance in y-coordinate.
 The instance method __str__ that return the current Point coodinates.
Answer
class Point:
def __init__(self):
self.x = 0
self.y = 0
def __init__(self, x, y):
self.x = x
self.y = y
def move(self, xInc, yInc):
self.x= self.x+ xInc
self.y= self.y+ yInc
def __str__(self):
return '('+ x+ ','+ y +')'
1
Download