Error
There was an error loading the page.
Exploration activity: Define a class, add methods to it, then use it
In four parts, the student builds up the definition of a class representing a rectangle. First they write the constructor, then add methods to compute area and perimeter.
In the final part, they must use the methods to write a function which determines if a rectangle's area is larger than its perimeter.
Metadata
-
England schools
-
England university
-
Scotland schools
Taxonomy: mathcentre
Taxonomy: Kind of activity
Taxonomy: Context
Contributors
Feedback
From users who are members of Programming extension :
![]() |
said | Needs to be tested | 3 years, 1 month ago |
![]() |
said | Doesn't work | 3 years, 1 month ago |
History
Christian Lawson-Perfect 1 year, 10 months ago
Published this.Christian Lawson-Perfect commented 3 years, 1 month ago
I've made this a bit more complete. Now there are two parts about adding methods, and a final part where you have to use them.
I've put the validation tests in variables, so each part uses the last part's tests plus some new ones.
George Stagg commented 3 years, 1 month ago
> I've changed the placeholder option for the widget to render(settings["placeholder"]), so it subs into curly braces.
How can I escape the curly braces for R code? I tried \{ which got rid of an error but the \ fell through into the output too.
Chris Graham commented 3 years, 1 month ago
Thanks for sorting the placeholder, that works how I hoped now.
The idea was to do the refactoring to build up a class in stages: given a list of methods and attributes, a student will naturally try to do the whole thing at once, then get an error and give up. So you might have some options for what other methods they want to add, or to add a subclass, etc. It was a proof of concept really, as I think the same idea could be applied to other bits of code.
Christian Lawson-Perfect 3 years, 1 month ago
Gave some feedback: Needs to be tested
Christian Lawson-Perfect commented 3 years, 1 month ago
Does it matter that the student is free to change their original class? I suppose refactoring is a natural thing, and they shouldn't be put off doing that.
Another way to do this would be to put the student's answer in the preamble, and ask them to make a class RectangleWithArea(Rectangle), inheriting from their previous one.
Christian Lawson-Perfect commented 3 years, 1 month ago
I've changed the placeholder option for the widget to render(settings["placeholder"]), so it subs into curly braces.
Chris Graham commented 3 years, 1 month ago
This was perhaps wishful thinking, but I was hoping that it might be possible to use the student's answer to the first explore mode part in the second, so that they could add to it.
Chris Graham 3 years, 1 month ago
Gave some feedback: Doesn't work
Chris Graham 3 years, 1 month ago
Created this.Name | Status | Author | Last Modified | |
---|---|---|---|---|
Exploration activity: Define a class, add methods to it, then use it | Needs to be tested | Chris Graham | 11/05/2023 08:07 | |
Exploration activity: Define a class, add methods to it, then use it | draft | Christian Lawson-Perfect | 04/07/2024 11:19 |
There are 5 other versions that do you not have access to.
Name | Type | Generated Value |
---|
last_code | string |
# Preamble (this will get repl
|
||||
validation1 | list |
Nested 4×2 list
|
||||
validation_area | list |
Nested 5×2 list
|
||||
validation_perimeter | list |
Nested 6×2 list
|
||||
validation_check_rectangle | list |
Nested 1×2 list
|
||||
postamble | string |
# Test variables
from random
|
Generated value: string
- "Create the Rectangle class" - variable replacement
- "Add an area method" - variable replacement
- "Add a perimeter method" - variable replacement
Use this tab to check that this question works as expected.
Part | Test | Passed? |
---|---|---|
Code | ||
Hasn't run yet | ||
Code | ||
Hasn't run yet | ||
Code | ||
Hasn't run yet | ||
Code | ||
Hasn't run yet |
This question is used in the following exam: