Option Strict On

Public MustInherit Class Building
  ' To jest klasa bazowa, z której wyprowadzamy 
  ' klasy Apartment, Commercial, Home.

  ' =============== Stałe symboliczne ================

  Private Const APARTMENT As Integer = 0
  Private Const COMMERCIAL As Integer = 1
  Private Const HOME As Integer = 2
  ' Domyślne numery telefonów do usuwania śniegu
  Public Const APTPHONE As String = "555-1000"
  Public Const COMPHONE As String = "555-2000"
  Public Const HOMPHONE As String = "555-3000"

  ' ================== Składniki danych ==================

  Private mAddress As String        ' Adres
  Private mPrice As Double          ' Cena nabycia
  Private mMonthlyPayment As Double ' Opłaty miesięczne 
  Private mTaxes As Double          ' Podatki roczne
  Private mType As Integer          ' Typ budynku
  Private mSnowPhone As String      ' Kogo wezwać do odśnieżania

  ' ================== Konstruktor ==================

  Public Sub New()
    Address = "Pusty budynek"
  End Sub


  ' ==================== Właściwości ======================

  Public Property Address() As String      ' Właściwość Adres
    Get
      Return mAddress
    End Get

    Set(ByVal Value As String)
      mAddress = Value
    End Set
  End Property

  Public Property PurchasePrice() As Double  ' Właściwość Cena nabycia
    Get
      Return mPrice
    End Get

    Set(ByVal Value As Double)
      mPrice = Value
    End Set
  End Property

  Public Property MonthlyPayment() As Double  ' Właściwość Opłaty miesięczne
    Get
      Return mMonthlyPayment
    End Get

    Set(ByVal Value As Double)
      mMonthlyPayment = Value
    End Set
  End Property

  Public Property Taxes() As Double   ' Właściwość Podatek od nieruchomości
    Get
      Return mTaxes
    End Get

    Set(ByVal Value As Double)
      mTaxes = Value
    End Set
  End Property

  Public Property BuildingType() As Integer   ' Własciwość Typ budynku 
    Get
      Return mType
    End Get

    Set(ByVal Value As Integer)
      If Value < APARTMENT Or Value > HOME Then
        mType = -1  ' błąd
      Else
        mType = Value
      End If
    End Set
  End Property

  Public Property SnowRemoval() As String    ' Wywołanie odśnieżania
    Get
      Return mSnowPhone
    End Get

    Set(ByVal Value As String)
      mSnowPhone = Value
    End Set
  End Property

  ' ========================== Metody ========================

  ' Zmuszamy klasy pochodne, aby podawały, do kogo dzwonić.
  Public MustOverride Function CallSnowRemoval() As String

  Protected Sub DisplayBaseInfo()
    Dim BldType As String

    ' Cel: wyświetlić podstawowe dane składowe 
    Select Case mType       ' Jaki typ budynku?
      Case APARTMENT
        BldType = "Apartment"
      Case COMMERCIAL
        BldType = "Commercial"
      Case HOME
        BldType = "Home"
    End Select
    Console.WriteLine()
    Console.WriteLine("---------- " & BldType & " -----------")
    Console.WriteLine("Address: " & mAddress)
    Console.WriteLine("Purchase Price: " & FormatMoney(mPrice))
    Console.WriteLine("Monthly Payment: " & _
                       FormatMoney(mMonthlyPayment))
    Console.WriteLine("Property Taxes: " & FormatMoney(mTaxes))
    Console.WriteLine("Building Type: " & BldType)
    Console.WriteLine("Snow removal Phone: " & mSnowPhone)
    Console.WriteLine()
  End Sub

  ' =========================== Programy pomocnicze ========================

  Protected Function FormatMoney(ByVal num As Double) As String
    ' Cel: formatowanie wartości dolara
    '
    ' Argumenty:
    '  num   Liczba typu double, która jest wartością dolara do 
    '        sformatowania
    '
    ' Zwracana wartość:
    '  string   Łańcuch wartości w formacie dolara

    Return Format(num, "$#,###,###,###.00")
  End Function

End Class

' ++++++++++++++++++++++++++++ Klasa Apartment ++++++++++++++++++++++++

Public Class Apartment
  Inherits Building

  Private mUnits As Integer    ' Liczba mieszkań
  Private mRent As Double      ' Cena najmu na jednostkę
  Private mOccupRate As Double ' Współczynnik zajęcia budynku 

  Public Sub New()

  End Sub

  ' Konstruktor z inicjalizujacą listą argumentów
  Public Sub New(ByVal Addr As String, ByVal Price As Double, _
            ByVal Payment As Double, ByVal Taxes As Double, _
            ByVal Bldg As Integer, ByVal SnowPhone As String)
    MyBase.Address = Addr
    MyBase.PurchasePrice = Price
    MyBase.MonthlyPayment = Payment
    MyBase.Taxes = Taxes
    MyBase.BuildingType = Bldg
    If SnowPhone = "" Then
      MyBase.SnowRemoval = APTPHONE
    Else
      MyBase.SnowRemoval = SnowPhone
    End If
  End Sub
  ' ==================== Właściwości ======================

  Public Property Units() As Integer    ' Mieszkania
    Get
      Return mUnits
    End Get
    Set(ByVal Value As Integer)
      mUnits = Value
    End Set
  End Property

  Public Property Rents() As Double     ' Koszty najmu
    Get
      Return mRent
    End Get
    Set(ByVal Value As Double)
      mRent = Value
    End Set
  End Property

  Public Property OccupancyRate() As Double ' Współczynnik zajęcia
    Get
      Return mOccupRate
    End Get
    Set(ByVal Value As Double)
      mOccupRate = Value
    End Set
  End Property

  ' ============== Metody ==================

  Public Overrides Function CallSnowRemoval() As String
    ' Cel: ta procedura jest wywoływana, aby usunąć śnieg przed blokiem.
    '    
    Return "Usuwanie śniegu przed blokiem: " & MyBase.SnowRemoval
  End Function

  Public Sub DisplayBuilding()

    DisplayBaseInfo()
    Console.WriteLine("Apartment members:")
    Console.WriteLine("Number of Units: " & mUnits)
    Console.WriteLine("Rent per Unit: " & FormatMoney(mRent))
    Console.WriteLine("Occupancy Rate: " & mOccupRate)
  End Sub
End Class

' ++++++++++++++++++++++++++++ Klasa Commercial ++++++++++++++++++++++++++

Public Class Commercial
  Inherits Building

  Private mSquareFeet As Integer  ' Powierzchnia do wynajęcia
  Private mRentPerSF As Double    ' Cena najmu
  Private mParking As Integer     ' Miejsca parkingowe

  Public Sub New()  ' Konstruktor bez argumentów

  End Sub

  Public Sub New(ByVal Addr As String, ByVal Price As Double, _
           ByVal Payment As Double, ByVal Taxes As Double, _
           ByVal Bldg As Integer, ByVal SnowPhone As String)
    MyBase.Address = Addr
    MyBase.PurchasePrice = Price
    MyBase.MonthlyPayment = Payment
    MyBase.Taxes = Taxes
    MyBase.BuildingType = Bldg
    If SnowPhone = "" Then
      MyBase.SnowRemoval = COMPHONE
    Else
      MyBase.SnowRemoval = SnowPhone
    End If
  End Sub

  ' ==================== Właściwości ======================

  Public Property SquareFeet() As Integer   ' Powierzchnia
    Get
      Return mSquareFeet
    End Get
    Set(ByVal Value As Integer)
      mSquareFeet = Value
    End Set
  End Property

  Public Property RentPerSF() As Double    ' Cena wynajmu
    Get
      Return mRentPerSF
    End Get
    Set(ByVal Value As Double)
      mRentPerSF = Value
    End Set
  End Property

  Public Property ParkingSpots() As Integer  ' Miejsca parkingowe
    Get
      Return mParking
    End Get
    Set(ByVal Value As Integer)
      mParking = Value
    End Set
  End Property

  ' ============== Metody ==================

  Public Overrides Function CallSnowRemoval() As String
    ' Cel: ta procedura jest wywoływana, aby usunąć śnieg przed budynkiem 
    '      komercyjnym.
    '      
    Return "Commercial snow removal: " & _
            MyBase.SnowRemoval
  End Function

  Public Sub DisplayBuilding()
    DisplayBaseInfo()        ' Wywołanie klasy bazowej
    Console.WriteLine("      Commercial members:")
    Console.WriteLine("Square Feet: " & mSquareFeet)
    Console.WriteLine("Rent per SF: " & FormatMoney(mRentPerSF))
    Console.WriteLine("Parking Spots: " & mParking)
  End Sub
End Class

' ++++++++++++++++++++++++++++ Klasa Home ++++++++++++++++++++++++++++

Public NotInheritable Class Home
  Inherits Building

  Private mSquareFeet As Integer    ' Powierzchnia domu
  Private mRentPerMonth As Double   ' Cena najmu na miesiąc
  Private mBedrooms As Integer      ' Liczba sypialni
  Private mBaths As Integer         ' Liczba łazienek

  ' ==================== Właściwości ======================

  Public Sub New()  ' Konstruktor bez argumentów

  End Sub

  Public Sub New(ByVal Addr As String, ByVal Price As Double, _
           ByVal Payment As Double, ByVal Taxes As Double, _
           ByVal Bldg As Integer, ByVal SnowPhone As String)
    MyBase.Address = Addr
    MyBase.PurchasePrice = Price
    MyBase.MonthlyPayment = Payment
    MyBase.Taxes = Taxes
    MyBase.BuildingType = Bldg
    If SnowPhone = "" Then
      MyBase.SnowRemoval = HOMPHONE
    Else
      MyBase.SnowRemoval = SnowPhone
    End If

  End Sub

  Public Property SquareFeet() As Integer    ' Powierzchnia w m2
    Get
      Return mSquareFeet
    End Get
    Set(ByVal Value As Integer)
      mSquareFeet = Value
    End Set
  End Property

  Public Property Rent() As Double       ' Cena najmu
    Get
      Return mRentPerMonth
    End Get
    Set(ByVal Value As Double)
      mRentPerMonth = Value
    End Set
  End Property

  Public Property Bedrooms() As Integer     ' Sypialnie
    Get
      Return mBedrooms
    End Get
    Set(ByVal Value As Integer)
      mBedrooms = Value
    End Set
  End Property

  Public Property Baths() As Integer       ' Łazienki
    Get
      Return mBaths
    End Get
    Set(ByVal Value As Integer)
      mBaths = Value
    End Set
  End Property

  ' ============== Metody ==================

  Public Overrides Function CallSnowRemoval() As String
    ' Cel: ta procedura wywołuje usuwanie śniegu przed domem.
    '      
    Return "Home snow removal: " & MyBase.SnowRemoval
  End Function

  Public Sub DisplayBuilding()

    MyBase.DisplayBaseInfo()        ' Wywołanie klasy bazowej
    Console.WriteLine("      Home members:")
    Console.WriteLine("Square Feet: " & mSquareFeet)
    Console.WriteLine("Rent per Month: " & _
            FormatMoney(mRentPerMonth))
    Console.WriteLine("Bedrooms: " & mBedrooms)
    Console.WriteLine("Baths: " & mBaths)
  End Sub
End Class
