Docstoc

payment

Document Sample
payment Powered By Docstoc
					Imports System
Imports System.Text


Public Class Payment
    Private account As String
    Private amount As Double
    Private authorized As Boolean
    Private billed As Boolean


    Public Sub New(ByVal account As String)
        Me.account = account
        authorized = False
        billed = False
        amount = 0
    End Sub


    Protected ReadOnly Property AccountNumber() As String
    Get
        Return Me.account
    End Get
    End Property


    Public Function Authorize(ByVal amount As Double) As Bool
        If authorized Then
             MessageBox.Show("Payment is already authorized")
        Else
            Me.amount = amount
            MessageBox.Show("Authorizing payment for " & amount)
            authorized = True
        End If
        Return authorized
    End Function


    Public Function Bill() As Boolean
        If authorized Then
              MessageBox.Show("Billing payment for " & amount)
              billed = True
        Else
            MessageBox.Show("Payment is not authorized")
        End If
        Return billed
    End Function


    Public Function Credit() As Boolean
        If billed Then
            MessageBox.Show("Crediting payment for ", amount)
            billed = False
            Return True
        Else
            MessageBox.Show("Payment is not authorized")
        End If
        Return False
    End Function


End Class


Public Class CreditCard
Inherits Payment


    Public Sub New(ByVal account As String)
        MyBase.New(account)
    End Sub


    Public Sub Verify()
        MessageBox.Show("Verifying...")
    End Sub

    Public Readonly Property DisplayNumber() As String
    Get
    'Faster than concatenating normal strings
        Dim sb As New StringBuilder()
        Dim account As String = Me.AccountNumber
        Dim len As Integer = account.length
        sb.Append(account.SubString(0, 1))
        sb.Append(New String("X"c, len - 5))
        sb.Append(account.SubString(len - 4, 4))
        Return sb.ToString()
    End Get
    End Property
End Class


Dim cc As New CreditCard("4111111111111111")
cc.Verify()


If cc.Authorize(3.33) Then
    If cc.Bill() Then
        cc.Credit()
    End If
End If

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:1
posted:2/17/2012
language:
pages:3