Question
Compose a test client for Rectangle that takes three command-line arguments n, lo, and hi; generates n random rectangles whose width and height are uniformly
Compose a test client for Rectangle that takes three command-line arguments n, lo, and hi; generates n random rectangles whose width and height are uniformly distributed between lo and hi in the unit square; draws those rectangles to standard drawing, and writes their average area and average perimeter to standard output.
import stddraw class Rectangle:
# Create rectangle with center (_x, _y),
# width w, and height h.
def __init__(self, _x, _y, w, h): self._x = _x self._y = _y self._width = w self._height = h
# The area of self.
def area(self): return self._width * self._height
# The perimeter of self.
def perimeter(self): return 2*(self._width * self._height)
# True if self intersects other; False otherwise.
def intersects(self, other): #check if one rectangle is to the left or right of other if((self._x+self._width/2)<(other._x-other._width/2) or (self._x-self._width/2)>(other._x+other._width/2)): return False #check if one rectangle is to the top or bottom of other if((self._y+self._height/2)<(other._y-other._height/2) or (self._y-self._height/2)>(other._y+other._height/2)): return False return True
# True if self contains other; False otherwise.
def contains(self, other):
if(self._x+self._width/2
# Draw self on stddraw.
def draw(self): stddraw.rectangle((self._x-self._width/2),(self._y-self._height/2), self._width, self._height)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started