Question: Using Python 3 Programming: State a class MovableRectangle that inherits from class Rectangle. This class has a supplementary instance variable, assumed to be boolean, called

Using Python 3 Programming:

State a class MovableRectangle that inherits from class Rectangle. This class has a supplementary instance variable, assumed to be boolean, called self.move. Implement in this class a constructor with three arguments, a point and two rational values, to be assigned to the three instance variables. self.move is initially always set to False. Your code MUST call the constructor of the superclass.

Write a method named unlock that sets self.move to True.

Write a method named lock that sets self.move to False.

Write a method named moveTo that takes an object of class Point as argument, and: If the rectangle is unlocked, moves it so as its new bottom left is the point given as argument. Otherwise, the method prints the following message: Warning: locked.

Write a method named toString that returns a string containing, on the same line, the string representing the bottom left corner, followed by the rectangle width and height, followed by the current status (locked or unlocked) formatted as follows (the values will di er depending on each object):

(5,15), W=2, H=2, Movable? True

(if it is locked, the end of string should be ...Movable? False).

Outside from the class, write the following statements: Create a movable rectangle r3 whose bottom left corner is p1, width is 2 and height is 2. Print the rectangle r3, using toString. Create a point p3 of coordinates (5; 15). Call the method moveTo on rectangle r3 in order to try moving its origin to p3. Print again the rectangle r3, using toString. Unlock r3. Call again the method moveTo on rectangle r3 in order to try moving its origin to p3. Print again the rectangle r3, using toString.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!