ps9, any tips on problem 2? I'm not sure how the functions in the ShapeSet class would even be called.
The functions in ShapeSet would be called very much like the functions in the handout for Lec16. ShapeSet is roughly analogous to the "Faculty" class that he created then. In brief, use dot notation: ss1 = ShapeSet(), area= ss1.area(), etc.
abmagil thank you. I started the class, but I'm not sure how to complete the str method. My current code is here: http://pastebin.com/2FBDgzUL Any suggestions? I've been looking for something in the lecture or reading to refer to.
Think about it this way: Shapes aren't a subclass of ShapeSets (in fact, the two classes bear no relation to each other, other than that we can/should write some code to ensure ShapeSets are populated with Shapes), so ShapeSets can't _inherit_ the methods we created in Shapes. However, once you create a method in a class, it's just like any other function/method call. That means you can call the methods from a specific shape in a ShapeSet. A good analogy, apart from the Faculty one from Lec 16, is a receipt at the supermarket. The receipt is the ShapeSet: a list of a certain type of things (groceries or Shape objects). The methods would be things like the price or the area (or string). Your receipt wouldn't have a price method and your ShapeSet wouldn't have an area method because they're just lists of things, though you could create those methods for convenience. What they have is calls of those methods for the objects (groceries) in them. Each grocery item has a price method, which would be called as apple.price(), pear.price(), etc. Same thing for your ShapeSet. Every object in it has a class (like Shape, Square, etc.) and those classes have methods associated. You can call those methods from inside the ShapeSet class.
Additionally, you will need to figure out how to display them sorted by type. I'm not sure the best way, but I sorted my list in situ during my addShapes method.
I dont understand the call to addShape as in the example to prob # 3 Is Triangle (1.2,2.5) one long string? I was thinking sh would be a tuple (shapestring, dimension) ie ('Circle', (4)). But his call to addShape has no comma between the shape and dimension. I cant do problem 2 until I understand what data structure I am passing around
Join our real-time social learning platform and learn together with your friends!