Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Visual Basic , Create an inheritance hierarchy that a bank might use to repre

ID: 3852561 • Letter: I

Question

In Visual Basic, Create an inheritance hierarchy that a bank might use to represent customer bank accounts. All customers at this bank can deposit (that is, credit) money into their accounts and withdraw (that is, debit) money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, don’t earn interest and charge a fee per transaction. Create base class Account and derived classes SavingsAccount and CheckingAccount that inherit from class Account. Base class Account should include a Private instance variable of type Decimal to represent the account balance. The class should provide a constructor that receives an initial balance and uses it to initialize the instance variable with a Public property. The property should validate the initial balance to ensure that it’s greater than or equal to 0.0. If not, the balance should be set to 0.0, and the Set accessor should throw an exception, indicating that the initial balance was invalid. The class should provide two Public methods. Method Credit should add an amount to the current balance. Method Debit should withdraw money from the Account and ensure that the debit amount does not exceed the Account’s balance. If it does, the balance should be left unchanged, and the method should throw an exception indicating that the debit amount exceeded the account balance. The class should also provide a Get accessor in property Balance that returns the current balance. Derived class SavingsAccount should inherit the functionality of an Account, but also include a Double instance variable indicating the interest rate (percentage) assigned to the Account. Class SavingsAccount’s constructor should receive the initial balance, as well as an initial value for the interest rate. SavingsAccount should provide Public method CalculateInterest that returns a Decimal indicating the amount of interest earned by an account. Method CalculateInterest should determine this amount by multiplying the interest rate by the account balance. [Note: SavingsAccount should inherit methods Credit and Debit without redefining them.] Derived class CheckingAccount should inherit from base class Account and include a Decimal instance variable that represents the fee charged per transaction. CheckingAccount’s constructor should receive the initial balance, as well as a parameter indicating a fee amount. Class Checking-Account should redefine methods Credit and Debit so that they subtract the fee from the account balance whenever either transaction is performed successfully. CheckingAccount’s versions of these methods should invoke the base-class Account version to perform the updates to an account balance. CheckingAccount’s Debit method should charge a fee only if money is actually withdrawn (that is, the debit amount does not exceed the account balance). After defining the classes in this hierarchy, write an app that creates objects of each class and tests their methods. Add interest to the SavingsAccount object by first invoking its Calculate- Interest method, then passing the returned interest amount to the object’s Credit method.

Explanation / Answer

Withdrawl form:

VERSION 5.00

Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomct2.ocx"

Begin VB.Form formWithdrawal

   BackColor       =   &H00FFFFFF&

   BorderStyle     =   1 'Fixed Single

   Caption         =   "WITHDRAWAL"

   ClientHeight    =   6375

   ClientLeft      =   45

   ClientTop       =   435

   ClientWidth     =   8895

   LinkTopic       =   "Form1"

   MaxButton       =   0   'False

   MDIChild        =   -1 'True

   MinButton       =   0   'False

   ScaleHeight     =   6375

   ScaleWidth      =   8895

   Begin VB.Frame Frame1

      Appearance      =   0 'Flat

      BackColor       =   &H80000005&

      ForeColor       =   &H80000008&

      Height          =   6375

      Left            =   0

      TabIndex        =   0

      Top             =   0

      Width           =   8895

      Begin VB.Frame Frame2

         Appearance      =   0 'Flat

         BackColor       =   &H80000005&

         Caption         =   "Account Number"

         BeginProperty Font

            Name            =   "....."

            Size            =   8.25

            Charset         =   0

            Weight          =   700

            Underline       =   0   'False

            Italic          =   0   'False

            Strikethrough   =   0   'False

         EndProperty

         ForeColor       =   &H80000008&

         Height          =   5175

         Left            =   120

         TabIndex        =   23

         Top             =   240

         Width           =   2055

         Begin VB.ComboBox cboAccountNumber

            BeginProperty Font

               Name            =   "......."

               Size            =   8.25

               Charset         =   0

               Weight          =   700

               Underline       =   0   'False

               Italic          =   0   'False

               Strikethrough   =   0   'False

            EndProperty

            Height          =   4665

            Left            =   120

            Style           =   1 'Simple Combo

            TabIndex        =   24

            Top             =   360

            Width           =   1815

         End

      End

      Begin VB.Frame Frame3

         Appearance      =   0 'Flat

         BackColor       =   &H80000005&

         Caption         =   "Transaction Details"

         BeginProperty Font

            Name            =   "......."

            Size            =   8.25

            Charset         =   0

            Weight          =   700

            Underline       =   0   'False

            Italic          =   0   'False

            Strikethrough   =   0   'False

         EndProperty

         ForeColor       =   &H80000008&

         Height          =   2175

         Left            =   2280

         TabIndex        =   17

         Top             =   3240

         Width           =   4095

         Begin VB.TextBox txtCheckNo

            Appearance      =   0 'Flat

            BeginProperty Font

               Name            =   "....."

               Size            =   8.25

               Charset         =   0

               Weight          =   700

               Underline       =   0   'False

               Italic          =   0   'False

               Strikethrough   =   0   'False

            EndProperty

            Height          =   315

            Left            =   1440

            MaxLength       =   50

            TabIndex        =   2

            Top             =   1320

            Width           =   2535

         End

         Begin VB.TextBox txtTransactionMode

            Appearance      =   0 'Flat

            BackColor       =   &H00E0E0E0&

            BeginProperty Font

               Name            =   "......"

               Size            =   8.25

               Charset         =   0

               Weight          =   700

               Underline       =   0   'False

               Italic          =   0   'False

               Strikethrough   =   0   'False

            EndProperty

            Height          =   315

            Left            =   1440

            Locked          =   -1 'True

            MaxLength       =   100

            TabIndex        =   18

            Text            =   "Withdrawal"

            Top             =   360

            Width           =   2535

         End

         Begin VB.TextBox txtAmount

            Appearance      =   0 'Flat

            BeginProperty Font

               Name            =   "......."

               Size            =   8.25

               Charset         =   0

               Weight          =   700

               Underline       =   0   'False

               Italic          =   0   'False

               Strikethrough   =   0   'False

            EndProperty

            Height          =   315

            Left            =   1440

            MaxLength       =   14

            TabIndex        =   3

            Top             =   1800

            Width           =   2535

         End

         Begin MSComCtl2.DTPicker dtpDate

            Height          =   375

            Left            =   1440

            TabIndex        =   19

            Top             =   840

            Width           =   2535

            _ExtentX        =   4471

            _ExtentY        =   661

            _Version        =   393216

            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}

               Name            =   ".........."

               Size            =   8.25

               Charset         =   0

               Weight          =   700

               Underline       =   0   'False

               Italic          =   0   'False

               Strikethrough   =   0   'False

          EndProperty

            Format          =   91422721

            CurrentDate     =   38954

         End

         Begin VB.Label Label9

            BackStyle       =   0 'Transparent

            Caption         =   "Check Number"

            Height          =   255

            Left            =   120

            TabIndex        =   28

            Top             =   1320

            Width           =   1215

         End

         Begin VB.Label Label5

            BackStyle       =   0 'Transparent

            Caption         =   "Transaction Date"

            Height          =   255

            Left            =   120

            TabIndex        =   22

            Top             =   840

            Width           =   1335

         End

         Begin VB.Label Label1

            BackStyle       =   0 'Transparent

            Caption         =   "Transaction Mode"

            Height          =   255

            Left            =   120

            TabIndex        =   21

            Top             =   360

            Width           =   1455

         End

         Begin VB.Label Label2

            BackStyle       =   0 'Transparent

            Caption         =   "Amount"

            Height          =   255

            Left            = 120

            TabIndex        =   20

            Top             =   1800

            Width           =   975

         End

      End

      Begin VB.Frame Frame5

         Appearance      =   0 'Flat

         BackColor       =   &H80000005&

         Caption         =   "Customer Details"

         BeginProperty Font

            Name            =   "........"

            Size            =   8.25

            Charset         =   0

            Weight          =   700

            Underline       =   0   'False

            Italic          =   0   'False

            Strikethrough   =   0   'False

         EndProperty

         ForeColor       =   &H80000008&

         Height          =   2895

         Left            =   2280

         TabIndex        =   5

         Top             =   240

         Width           =   4095

         Begin VB.Frame Frame7

            Appearance      =   0 'Flat

            BackColor       =   &H80000005&

            BorderStyle     =   0 'None

            Enabled         =   0   'False

            ForeColor       =   &H80000008&

            Height          =   2535

            Left            =   120

            TabIndex        =   6

            Top             =   240

            Width           =   3855

            Begin VB.TextBox txtAccountType

               Appearance      =   0 'Flat

               BackColor       =   &H00E0E0E0&

               BeginProperty Font

                  Name            =   "......"

                  Size           =   8.25

                  Charset         =   0

                  Weight          =   700

                  Underline       =   0   'False

                  Italic          =   0   'False

                  Strikethrough   =   0   'False

               EndProperty

               Height          =   315

               Left            =   1320

               MaxLength       =   10

               TabIndex        =   11

               Top             =   1560

               Width           = 2535

            End

            Begin VB.TextBox txtBalance

               Appearance      =   0 'Flat

               BackColor       =   &H00E0E0E0&

               BeginProperty Font

                  Name            =   "......."

                  Size            =   8.25

                  Charset         =   0

                  Weight          =   700

                  Underline       =   0   'False

                  Italic          =   0   'False

                  Strikethrough   =   0   'False

               EndProperty

               Height          =   315

               Left            =   1320

               Locked          =   -1 'True

               MaxLength       =   100

               TabIndex        =   9

               Top             =   2040

               Width           =   2535

            End

            Begin VB.TextBox txtGender

               Appearance      =   0 'Flat

               BackColor       =   &H00E0E0E0&

               BeginProperty Font

                  Name            =   "........."

                  Size            =   8.25

                  Charset         =   0

                  Weight          =   700

                  Underline       =   0   'False

                  Italic          =   0   'False

                  Strikethrough   =   0   'False

               EndProperty

               Height          =   315

               Left            =   1320

               MaxLength       =   10

               TabIndex        =   7

               Top             =   1080

               Width           =   2535

            End

            Begin VB.Label Label4

               BackStyle       =   0 'Transparent

               Caption         =   "Account Type"

               Height          =   255

               Left            =   0

               TabIndex        =   16

               Top             =   1560

               Width           =   1215

            End

            Begin VB.Label Label3

               BackStyle       =   0 'Transparent

               Caption         =   "Gender"

               Height          =   255

               Left            =   0

               TabIndex        =   12

               Top             =   1080

               Width           =   1815

            End

         End

      End

    

Attribute VB_Name = "formWithdrawal"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

Private Sub cboAccountNumber_Click()

On Error GoTo errhandler

    Call DisplayCustomerDetails(cboAccountNumber.Text)

    txtBalance.Text = Balance

    txtFirstName.Text = FirstName

    txtLastName.Text = LastName

    txtGender.Text = Gender

    txtAccountType.Text = AccountType

cmdOk.Enabled = True

    txtAmount.Enabled = True

    txtCheckNo.Enabled = True

    txtCheckNo.SetFocus

Pic.Picture = LoadPicture(App.Path & "pictures" & CustomerPicture)

EXITPROCEDURE:

    Exit Sub

errhandler:

    Pic.Picture = LoadPicture(App.Path & "Pictures" & "NA.GIF")

    GoTo EXITPROCEDURE

End Sub

Private Sub cboAccountNumber_KeyPress(KeyAscii As Integer)

    KeyAscii = 0

End Sub

Private Sub cmdClose_Click()

    If MsgBox("Are you sure you want to cancel ?", 4 + 32, title) = vbNo Then

        GoTo EXITPROCEDURE

        Else

            Unload Me

    End If

EXITPROCEDURE:

    Exit Sub

End Sub

Private Sub cmdOk_Click()

On Error GoTo errhandler

If txtCheckNo.Text = "" Then

        MsgBox "Please enter check number!", vbExclamation, title

        txtCheckNo.SetFocus

        GoTo EXITPROCEDURE

    End If

If txtAmount.Text = "" Then

        MsgBox "Please enter Amount!", vbExclamation, title

        txtAmount.SetFocus

        GoTo EXITPROCEDURE

    End If

If Check_CheckNo(txtCheckNo.Text) = True Then

        MsgBox "Check Number has already been used", vbExclamation, title

        txtCheckNo.SelStart = 0

        txtCheckNo.SelLength = Len(txtCheckNo.Text)

        txtCheckNo.SetFocus

        GoTo EXITPROCEDURE

    End If

If Trim(txtAmount.Text) > Trim(txtBalance.Text) Then

        MsgBox "The Amount you are withdrawing is more than your current balance!", vbExclamation, title

        txtAmount.SelStart = 0

        txtAmount.SelLength = Len(txtAmount.Text)

        txtAmount.SetFocus

        GoTo EXITPROCEDURE

    End If

If Check_StopCheckNo(txtCheckNo.Text, cboAccountNumber.Text) = True Then

        MsgBox "Check Number has been stopped. You can not withdraw money with it", vbExclamation, title

        txtCheckNo.SelStart = 0

        txtCheckNo.SelLength = Len(txtCheckNo.Text)

        txtCheckNo.SetFocus

        GoTo EXITPROCEDURE

    End If

If MsgBox("Are you sure you want to withdraw " & txtAmount.Text & " from Account Number " & cboAccountNumber.Text & " ?", 4 + 32, title) = vbNo Then

        GoTo EXITPROCEDURE

        Else

            recTrans.AddNew

recTrans!TransactionID = autogen

                recTrans!TransactionDate = dtpDate.Value

                recTrans!TransactionType = "Withdrawal"

                recTrans!TransactionMode = "Cash"

                recTrans!FromAccountNumber = cboAccountNumber.Text

                recTrans!ToAccountNumber = ""

                recTrans!checkNumber = txtCheckNo.Text

                recTrans!Amount = txtAmount.Text

                recTrans!status = ""

recTrans.Update

con.Execute "Update Customer set Balance = " & CCur(txtBalance.Text) - CCur(txtAmount.Text) & " Where AccountNumber = '" & Trim(cboAccountNumber.Text) & "'"

MsgBox "Transaction done successfully.", vbExclamation, title

Unload Me

    End If

EXITPROCEDURE:

    Exit Sub

errhandler:

    MsgBox "An Error occurred. Transaction was unsuccessfull, Try again", vbCritical, title

    GoTo EXITPROCEDURE

End Sub

Private Sub Form_Load()

On Error GoTo errhandler

Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3

    Call ConnectMe

    cmdOk.Enabled = False

    txtAmount.Enabled = False

    txtCheckNo.Enabled = False

    dtpDate.Value = Date

Call fill_Combo(cboAccountNumber)

EXITPROCEDURE:

    Exit Sub

  errhandler:

    MsgBox "An Error occurred while loading the form", vbCritical, title

    GoTo EXITPROCEDURE

End Sub

Private Sub txtAmount_KeyPress(KeyAscii As Integer)

    Call onlyNumbers(KeyAscii)

End Sub

Public Function autogen() As String

On Error GoTo errhandler

    Dim rec As New Recordset

rec.Open "select max(TransactionID) from Trans", con, adOpenDynamic, adLockOptimistic

   

    If rec.EOF Then

        autogen = 1

        Else

        autogen = Val(rec(0) + 1)

    End If

   

EXITPROCEDURE:

    Exit Function

   

errhandler:

    'MsgBox "An Error occurred. Transaction was unsuccessfull, Try again", vbCritical, title

    GoTo EXITPROCEDURE

End Function

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote