Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In simple Python: we are writing two version of a class that will use the same tst code and will work. Write a class definition

In simple Python: we are writing two version of a class that will use the same tst code and will work. Write a class definition Block, which stores information about the position and size of a rectangular block. None of your attributes should be public, meaning the attribute names should each start with a double underscore. Both versions will have the exact same methods (including the magic methods). The only difference will be how the size and location of the Block is stored. More specificially:

Version 1 should have attributes to store the coordinates of the center of the Block (either as separate x- and y-coordinates or as a pair* of numbers), and for the width and height of the Block. Note: this version should not have any attributes that have anything to do with the corners.

Version 2 should have attributes to store the coordinates of the bottom-left corner (the "SW"** corner) and the coordinates of the upper-right corner (the "NE"** corner). These can be stored either as four separate numbers or as two pairs...this version should not have any attributes that have anything to do with the center of the Block, nor should there be attributes for the width or height. Both versions should have a constructor that will either take a pair of coordinates (for the center), along with the width and height; or take two pairs of coordinates (representing the lower-left ("SW") and upper-right ("NE") corners). Note that the implementation for each version will be very different:

In version 1, the center-width-height case will be easy (since you'll be directly working with the coordinates of the center and the width and the height, and that's what you need to set), but the two-corner case will be harder (since you'll have to calculate the center and width and height by using the corner coordinates). Version2 the center-width-height case will be harder.

Both versions should have a getter method called .get_corner() that takes a string representing which corner ("SW": bottom-left, "SE": bottom-right, "NW": top-left, or "NE": top-right), and returns a pair representing the coordinates of that corner. So for example, block1.get_corner("NE") would return a tuple representing the coordinates of the top-right corner of block1. As with most of the methods for this class, the implementations for the two versions will be very different.

Both versions should have getter methods called .get_width() and .get_height() that return the width or height of the Block. Both versions should have a getter method called .get_center() that returns the coordinates of the center of the Block. Both versions need to have an appropriate .__repr__() method. Both versions should have a method called .move() that takes two numbers representing the distance to move (the first argument represents movement to the right and the second represents movement up). Both versions must have a setter method called .set_size() that takes two numbers representing a new width and a new height and resizes the Block accordingly. When resizing, the center of the Block should not move.

When you've got .set_size() working with two arguments, go back and alter the definition so that it also works with just one argument, using the same value for both the width and height.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Students also viewed these Databases questions

Question

Explain the steps involved in developing a QSPM.

Answered: 1 week ago

Question

(c) Calculate a 90% upper confidence limit for the error variance .

Answered: 1 week ago