Skip to content

Commit 0fbbb84

Browse files
committed
Working on final exam problems & solutions.
1 parent 6cf02c5 commit 0fbbb84

1 file changed

Lines changed: 45 additions & 26 deletions

File tree

source/solutions/oop/inheritance.md

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,58 @@ tags:
1919

2020
## Problem
2121

22-
Consider the following diagram:
22+
#. Consider the following diagram:
2323

24-
!include uml/cla/RoomClassroomOffice.md
24+
!include uml/cla/RoomClassroomOffice.md
2525

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
2727

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+
```
3131

32-
displays
32+
displays
3333

34-
```text
35-
UH 243
36-
```
34+
```text
35+
UH 243
36+
```
3737

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.
3939

40-
<details><summary>Solution</summary>
41-
```
42-
!include code/projects/RoomClassroomOffice/RoomClassroomOffice/Classroom.cs
43-
```
44-
</details>
40+
<details><summary>Solution</summary>
41+
```
42+
!include code/projects/RoomClassroomOffice/RoomClassroomOffice/Classroom.cs
43+
```
44+
</details>
4545

46-
#. 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
4747

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.
5272

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

Comments
 (0)