06 Teach : Team Activity
Overview
Create a class to represent a Circle, based on a provided Point class. It has a center (x, y) and a radius. Because a Circle has an x and a y coordinate, and more, one way to view it, would be to consider that a Circle IS-A Point. In this case, the Circle class would inherit from the Point class and simply add a radius to it.
On the other hand, another way to view the problem is to consider that a circle HAS-A point as its center and then also has a radius. With this approach the Circle would not inherit from the Point class, but rather, would have a member variable that is of type Point.
For this activity, we will explore both options, first focusing on the IS-A relationship, and then the HAS-A approach.
Instructions
Begin by creating a simple point class to match the following diagram:
| Point |
|---|
| x : float |
| y : float |
| prompt_for_point() : None |
| display() : None |
Core Requirements
Create the
Pointclass as defined above. Then, create theCircleclass as follows:Create a
Circleclass that inherits from, or extends, thePointclass.Create a blank method for
prompt_for_circleand display.In main, call these functions and ensure that everything compiles.
Implement the
prompt_for_circlemethod. It should ask for aCircleas follows:Enter x: 1 Enter y: 2 Enter radius: 3Please note that the
Pointclass will have a method calledprompt_for_point. Make sure you call this from your method to reuse code!Implement the display method. It should display a
Circleas follows:Center: (1, 2) Radius: 3Please note that the
Pointclass will have a method calleddisplay. Make sure you call this from your method to reuse code! (Yes, these methods should both be called "display".)
Stretch Challenges
After completing the above steps, make sure that everyone on the entire team is to this point and understands the material. Then, if you have time, move onto the following stretch challenges.
For the stretch challenge, you will repeat the activity using a HAS-A relationship.
-
Make a copy of your code from before, and start with the same Point class as before. This time your
Circleshould NOT inherit fromPoint, but rather should have aPointas a member variable calledcenter. -
Implement the
prompt_for_circleanddisplaymethods for your Circle class as before. Discuss with your team the pros and cons of the IS-A vs HAS-A approach to this problem. Determine which approach you feel is best and why. You'll provide your thoughts on this in your ponder submission for the week.
Instructor's Solution
As a part of this team activity, you are expected to look over a solution from the instructor to compare your approach to that one. One of the questions on the I-Learn submission will ask you to provide insights from this comparison.
Please DO NOT open the solution until you have worked through this activity as a team for the one hour period. At the end of the hour, if you are still struggling with some of the core requirements, you are welcome to view the instructor's solution and use it to help you complete your own code. Even if you use the instructor's code to help you, you are welcome to report that you finished the core requirements, if you code them up yourself.
After working with your team for the one hour activity, click here for the instructor's solution.
Submission
When you have finished this activity, please fill out the assessment in I-Learn. You are welcome to complete any additional parts of this activity by yourself or with others after the team meeting before submitting the assessment.