Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: Type a version of move_rectangle that creates and returns a new Rectangle instead of modifying the old one. Rectangle should have the following

Question: Type a version of move_rectangle that creates and returns a new Rectangle instead of modifying the old one.

 

Rectangle should have the following dimensions:
width = 100.00
height = 200.00

 

The location of the corner is:
x = 50
y = 50

 

Move the rectangle by the following
x = 50
y = 100The old rectangle should retain the original location.

 

 

Expected Outcome(output):

First box location before move:
50.0
50.0
New box with new location:
100.0
150.0
Old box location:
50.0
50.0

 

python file:

 

import copy

import math






 

def move_rectangle(box, dx, dy):

  """Move the Rectangle by modifying its corner object.

  rect: Rectangle object.

  dx: change in x coordinate (can be negative).

  dy: change in y coordinate (can be negative).

  """

  box.corner.x += dx

  box.corner.y += dy

 

def move_rectangle_copy(box, dx, dy):

    """Move the Rectangle and return a new Rectangle object.

    rect: Rectangle object.

    dx: change in x coordinate (can be negative).

    dy: change in y coordinate (can be negative).

    returns: new Rectangle

    """



 

    return new


 

def main():






 

    print('First box location before move:')




 

    print('New box with new location:')



 

   

    print('Old box location:')




 

if __name__ == '__main__':

    main()  

 




Step by Step Solution

There are 3 Steps involved in it

Step: 1

Sure Heres a possible implementation of moverectanglecopy def moverectanglecopybox dx dy newbox copy... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions

Question

4 What is specific in constructivist approach to group coaching?

Answered: 1 week ago