Question: Using Python 3 Programming: State a class Point that has two instance variables, its rational coordinates self.x and self.y. Implement in this class a constructor
Using Python 3 Programming:
State a class Point that has two instance variables, its rational coordinates self.x and self.y.
Implement in this class a constructor with two arguments, the values of the coordinates. Each argument should have a default value 0.0, allowing to call this method without arguments.
Write two methods named getX and getY that respecitvely return the value of self.x and the value of self.y.
Write a method named setX that takes a rational value as argument and modifies self.x so as it becomes equal to this value.
Write a method named setY that takes a rational value as argument and modifies self.y so as it becomes equal to this value.
Write a method named toString that returns a string containing the two coordinates of the point self, within parenthesis and separated by a comma.
Write a method named equals that takes another object of class Point as argument and returns True if the x and y coordinates of this points are equal to the x and y coordinates of self, and returns False otherwise.
Outside from the class, write the following statements: Create a point p1 of coordinates (0, 0) and un point p2 of coordinates (1, 2). Print out the coordinates of the two points on the same line, by calling toString on the two points. Print the result of applying the method equals on point p1, using p2 as argument. Set the x coordinate of p2 equal to the x coordinate of p1, using the methods setX and getX. Set the y coordinate of p2 equal to the y coordinate of p1, using the method setY and getY. Print again the result of applying the method equals on point p1, using p2 as argument. Increment by 1 the x coordinate of p2, using the methods setX and getX . Print again the result of applying the method equals on point p1, using p2 as argument.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
