Questions
- What is the keyword used to call the constructor from the base class?
-
this
. - the name of the base class.
-
base
-
over
-
inherits
Problems
- Consider the diagram representing the “Room”, “ClassRoom”, “Office” classes and their relations.
Suppose you are given an implementation of the Room
class, such that
displays
-
Write an implementation of the
ClassRoom
class. YourToString
method should display the room’s building and number, in addition to whether it has AV set-up.Solution
-
Write a
SameBuilding
static method to be placed inside theRoom
class such thatWould display “true” and “false”.
Solution
-
Consider the diagram representing the “Article”, “Book” classes and their relations.
-
Write a (partial) implementation of the
Article
abstract class:- 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 anArgumentOutOfRangeException
exception being thrown. - Write an abstract
ShippingCosts()
method.
Solution
- Write an implementation for the
-
Now, assume given a complete implementation of the
Article
abstract class. Write a complete implementation of theBook
class (header included), containing:- An implementation of the
Title
property using auto-properties. - A
Book
constructor that passes theidP
andpriceP
arguments to theArticle
constructor. ThetitleP
argument should be assigned to theTitle
property. - A
ShippingCosts()
method that returns either 5.0, or 10% of the Book’s price, whichever is smallest.
Solution
- An implementation of the
-
Write statements that, if placed in a
Main
method, would- Create a
Book
withId
“AAA001”,price
$12.5, titled “What it’s like to be a bird”. - Display (nicely) its shipping costs.
- Display its
Id
(as retrieved from the object).
Solution
(Download this code){.download-button}
- Create a
-