Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

This page removed for FERPA compliance
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Final Exam Review Spring 2006: Working with classes

Questions? Post them here.

would this work for b.)?

class REMOVED:
  def __init__(self):
    self.setDefaultColor()
    self.size=10
    self.position=(10,10)
    self.setColor()
  def setDefaultColor(self):
    self.color = red
  def draw(self,canvas):
    addRectFilled(canvas,self.position[0],self.position[1],self.size,self.size,self.color)
  def setColor(self):
    self.color = blue

No. REMOVED your setColor function. It needs to take in a generic color, not just blue. -Student2042

c)

class REMOVED:
  def __init__(self):
    self.setDefaultColor()
    self.size=10
    self.position=(10,10)
  def setDefaultColor(self):
    self.color = red
  def draw(self,canvas):
    addRectFilled(canvas,self.position[0],self.position[1],self.size,self.size,self.color)
  def grow(self, size)
    self.size = self.size + size

You only need to set self.size to what you pass in. After you call grow, you have to recall draw, and draw will grab the size for both the width and height.-Student2042

i am totally confused about this question – can i get a hint as to where to start. thanks!

page 325 off the textbook

when the default color is already set to red, how can you change it without actually removing "red" from the code?
You don't remove the default color. You create a function to change it.-Student2042


(a)
a red box 10 pixels long at (10,10) against a white background of size (400,200)
REMOVED background. makeEmptyPicture makes a completely black backgroung.-Student2042
(b)
def setColor(self, input):
self.color = input

(c)
def setSize(self, input):
self.size = input

(d)
def setPosition(self, input):
self.position = (input[0], input[1])

(e)
a box like in (a) but it will be blue instead of red.

yea?



Link to this Page