Python OOP with Dynamic Typing

I need help with this short Python homework about shapes, link to the assignment page is here https://sites.google.com/cs.stonybrook.edu/cse-216/assignments_1/assignment-5-oop-with-dynamic-typing


You can download the code on the page or you can also see the attached files below.


Some clarifications- in order to check equality of shapes for each class, you want them to have the same type and same coordinates. For the TwoDPoint Class,where the TODO magic method is, p is self and q is other, and adding/subtracting would mean x1-x2 and so on.

Get Help With a similar task to - Python OOP with Dynamic Typing

Login to view and/or buy answers.. or post an answer
Additional Instructions:

hw5codebase/quadrilateral.py from .two_d_point import TwoDPoint from typing import Tuple class Quadrilateral: def __init__(self, *floats): points = TwoDPoint.from_coordinates(list(floats)) self.__vertices = tuple(points[0:3]) @property def vertices(self): return self.__vertices def side_lengths(self): """Returns a tuple of four floats, each denoting the length of a side of this quadrilateral. The value must be ordered clockwise, starting from the top left corner.""" return 0, 0, 0, 0 # TODO def smallest_x(self): """Returns the x-coordinate of the vertex with the smallest x-value of the four vertices of this quadrilateral.""" return 0 # TODO hw5codebase/rectangle.py from .quadrilateral import Quadrilateral from .two_d_point import TwoDPoint class Rectangle(Quadrilateral): def __init__(self, *floats): super().__init__(*floats) if not self.__is_member(): raise TypeError("A rectangle cannot be formed by the given coordinates.") def __is_member(self): """Returns True if the given coordinates form a valid rectangle, and False otherwise.""" return False # TODO def center(self): """Returns the center of this rectangle, calculated to be the point of intersection of its diagonals.""" return TwoDPoint(0, 0) # TODO def area(self): """Returns the area of this rectangle. The implementation invokes the side_lengths() method from the superclass, and computes the product of this rectangle's length and width.""" return 0 # TODO hw5codebase/square.py from .rectangle import Rectangle from .quadrilateral import Quadrilateral class Square(Rectangle): def __init__(self, *floats): super().__init__(*floats) if not self.__is_member(): raise TypeError("A square cannot be formed by the given coordinates.") def snap(self): """Snaps the sides of the square such that each corner (x,y) is modified to be a corner (x',y') where x' is the integer value closest to x and y' is the integer value closest to y. This, of course, may change the shape to a general quadrilateral, hence the return type. The only exception is when the square is positioned in a way where this approximation will lead it to vanish into a single point. In that case, a call to snap() will not modify this square in any way.""" return Quadrilateral() # TODO hw5codebase/two_d_point.py from typing import List class TwoDPoint: def __init__(self, x, y) -> None: self.__x = x self.__y = y @property def x(self): return self.__x @property def y(self): return self.__y def __eq__(self, other: object) -> bool: return False # TODO def __ne__(self, other: object) -> bool: return not self.__eq__(other) def __str__(self) -> str: return '(%g, %g)' % (self.__x, self.__y) # TODO: add magic methods such that two TwoDPoint objects can be added and subtracted coordinate-wise just by using # syntax of the form p + q or p - q @staticmethod def from_coordinates(coordinates: List[float]): if len(coordinates) % 2 != 0: raise Exception("Odd number of floats given to build a list of 2-d points") points = [] it = iter(coordinates) for x in it: points.append(TwoDPoint(x, next(it))) return points

Related Questions

Similar orders to Python OOP with Dynamic Typing
9
Views
0
Answers
Send an email, with the current weather information from the target zip code with the weather information.
Create a web form to capture an email address and zip code along with a submit button Create a code behind to consume API from weatherapi.com Send an email, captured from the ‘email to’ textbox, with the current weather information from the t...
12
Views
0
Answers
JAVA project/paper/UML diagram
Java code (150 lines) paper(500 words) UML diagram In addition to the correctness of your code, part of your grade will be based on how organized your code is – how easy is it to read and understand. Proper spacing will aid you in this regard....
31
Views
0
Answers
Project for CS1302 using JavaFX
THE DEADLINE IS TODAY(4/21) AT 11:00!! It's not updating for some reason. I have done some of this project but it's not working and I need someone to complete it. There is a project description file, as well as my current java files. According to the desc...
13
Views
0
Answers
unity programming assignment help
Look at pdf, I can't explain well Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...