You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/solutions/oop/inheritance.md
+45-26Lines changed: 45 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,39 +19,58 @@ tags:
19
19
20
20
## Problem
21
21
22
-
Consider the following diagram:
22
+
#. Consider the following diagram:
23
23
24
-
!include uml/cla/RoomClassroomOffice.md
24
+
!include uml/cla/RoomClassroomOffice.md
25
25
26
-
Suppose you are given an implementation of the `Room` class, such that
26
+
Suppose you are given an implementation of the `Room` class, such that
27
27
28
-
```
29
-
!include`snippetStart="// Question 1",snippetEnd="// Refer to Classroom.cs for a solution"` code/projects/RoomClassroomOffice/RoomClassroomOffice/Program.cs
30
-
```
28
+
```
29
+
!include`snippetStart="// Question 1",snippetEnd="// Refer to Classroom.cs for a solution"` code/projects/RoomClassroomOffice/RoomClassroomOffice/Program.cs
30
+
```
31
31
32
-
displays
32
+
displays
33
33
34
-
```text
35
-
UH 243
36
-
```
34
+
```text
35
+
UH 243
36
+
```
37
37
38
-
#. Write an implementation of the `ClassRoom` class. Your `ToString` method should display the room's building and number, in addition to whether it has AV set-up.
38
+
#. Write an implementation of the `ClassRoom` class. Your `ToString` method should display the room's building and number, in addition to whether it has AV set-up.
#. Write a `SameBuilding` static method to be placed inside the `Room` class such that
46
+
#. Write a `SameBuilding` static method to be placed inside the `Room` class such that
47
47
48
-
```
49
-
!include`snippetStart="// Question 2",snippetEnd="// Refer to Room.cs for a solution.",dedent=4` code/projects/RoomClassroomOffice/RoomClassroomOffice/Program.cs
50
-
```
51
-
Would display "true" and "false".
48
+
```
49
+
!include`snippetStart="// Question 2",snippetEnd="// Refer to Room.cs for a solution.",dedent=4` code/projects/RoomClassroomOffice/RoomClassroomOffice/Program.cs
50
+
```
51
+
Would display "true" and "false".
52
+
53
+
<details><summary>Solution</summary>
54
+
```
55
+
!include`snippetStart="// (not on UML diagram)",snippetEnd="// Note that since we are inside the class,"` code/projects/RoomClassroomOffice/RoomClassroomOffice/Room.cs
56
+
```
57
+
</details>
58
+
59
+
#. Consider the following diagram:
60
+
61
+
!include uml/cla/Article.md
62
+
63
+
#. Write a (partial) implementation of the `Article` abstract class:
64
+
65
+
#. Write an implementation for the `price` attribute: you can either use a getter and a setter (as pictured in the UML diagram), or a property. However, in both cases, setting the price to a negative value should result in an `ArgumentOutOfRangeException` (that you can shorten to `AOORE`) exception being thrown.
66
+
#. Write an *abstract* `ShippingCosts()` method.
67
+
68
+
#. Now, assume given a complete implementation of the `Article` abstract class. Write a **complete** implementation of the `Book` class (header included), containing:
69
+
#. An implementation of the `Title` property using auto-properties.
70
+
#. A `Book` constructor that passes the `idP` and `priceP` arguments to the `Article` constructor. The `titleP` argument should be assigned to the `Title` property.
71
+
#. A `ShippingCosts()` method that returns either $5.0$, or 10% of the Book's price, whichever is smallest.
52
72
53
-
<details><summary>Solution</summary>
54
-
```
55
-
!include`snippetStart="// (not on UML diagram)",snippetEnd="// Note that since we are inside the class,"` code/projects/RoomClassroomOffice/RoomClassroomOffice/Room.cs
56
-
```
57
-
</details>
73
+
#. Write statements that, if placed in a `Main` method, would
74
+
#. Create a `Book` with `Id` "AAA001", `price` $12.5, titled "What it's like to be a bird".
75
+
#. Display (nicely) its shipping costs.
76
+
#. Display its `Id` (as retrieved from the object).
0 commit comments