|
19 | 19 |
|
20 | 20 | ## Problem |
21 | 21 |
|
22 | | -#. Consider the following diagram: |
| 22 | +#. Consider the diagram representing the "Room", "ClassRoom", "Office" classes and their relations. |
23 | 23 |
|
24 | 24 | !include uml/cla/RoomClassroomOffice.md |
25 | 25 |
|
@@ -56,21 +56,41 @@ tags: |
56 | 56 | ``` |
57 | 57 | </details> |
58 | 58 |
|
59 | | -#. Consider the following diagram: |
| 59 | +#. Consider the diagram representing the "Article", "Book" classes and their relations. |
60 | 60 |
|
61 | 61 | !include uml/cla/Article.md |
62 | 62 |
|
63 | 63 | #. Write a (partial) implementation of the `Article` abstract class: |
64 | 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. |
| 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` exception being thrown. |
66 | 66 | #. Write an *abstract* `ShippingCosts()` method. |
67 | 67 |
|
| 68 | + <details><summary>Solution</summary> |
| 69 | + ``` |
| 70 | + !include code/projects/Article/Article/Article.cs |
| 71 | + ``` |
| 72 | + </details> |
| 73 | + |
| 74 | + |
68 | 75 | #. Now, assume given a complete implementation of the `Article` abstract class. Write a **complete** implementation of the `Book` class (header included), containing: |
69 | 76 | #. An implementation of the `Title` property using auto-properties. |
70 | 77 | #. 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. |
| 78 | + #. A `ShippingCosts()` method that returns either 5.0, or 10% of the Book's price, whichever is smallest. |
| 79 | + |
| 80 | + <details><summary>Solution</summary> |
| 81 | + ``` |
| 82 | + !include code/projects/Article/Article/Book.cs |
| 83 | + ``` |
| 84 | + </details> |
72 | 85 |
|
73 | 86 | #. Write statements that, if placed in a `Main` method, would |
74 | 87 | #. Create a `Book` with `Id` "AAA001", `price` $12.5, titled "What it's like to be a bird". |
75 | 88 | #. Display (nicely) its shipping costs. |
76 | 89 | #. Display its `Id` (as retrieved from the object). |
| 90 | + |
| 91 | + <details><summary>Solution</summary> |
| 92 | + ```{download="code/projects/Article.zip"} |
| 93 | + !include code/projects/Article/Article/Program.cs |
| 94 | + ``` |
| 95 | + </details> |
| 96 | + |
0 commit comments