Coding Exercise: Classes
Test yourself on classes.
We'll cover the following
Problem
This exercise on creates a class for a house inventory program. Create a console-based application called House Inventory App that meets the requirements below.
-
Create a class and name it
House
. -
The
House
class must have the following properties:Address
asstring
Size
asint
Price
asint
-
Define two constructors in the
House
class.- The first constructor receives no argument and sets default values to the properties (the default value for
string
is an empty string, and forint
it’s0
). - The second constructor must receive and set the values for
Address
,Size
, andPrice
as arguments.
- The first constructor receives no argument and sets default values to the properties (the default value for
-
Create a method named
DisplayHouseDetails
in the class to display the properties of the object in the following format:
Address: {address} / Size: {size} / Price: {price} dollars.
Sample input
The class object is created with the following constructor parameters:
"Mark St.", 1500, 30000
Expected output
Address: Mark St. / Size: 1500 / Price: 300000 dollars.
Get hands-on with 1200+ tech skills courses.