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.

  1. Create a class and name it House.

  2. The House class must have the following properties:

    • Address as string
    • Size as int
    • Price as int
  3. 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 for int it’s 0).
    • The second constructor must receive and set the values for Address, Size, and Price as arguments.
  4. 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.