LAB 3 – CREATING AND USING VARIABLE OBJECTIVE: The main objective is to introduce the students with variables. Students will be able to know how to create and use the variables defined by them in the program. QUESTIONS: 1. Using the class Account as attached in the appendix, write a program that simulates a user bank account. A text box allows user to enter the amount of money to be deposited into or withdrawn from the account when the Deposit or Withdraw button is pressed. The current balance of the account is continuously displayed on the form. An example is shown on the left.
Create a new VB project named myBankAccount Add the Account class to the project: i. Select Project -> Add Class to open ‘Add New Item’ window. ii. Set the name to Account.vb and click Add button. iii. In the Account class code window, add the definition of the Account class as given in Lecture 4 between the lines ‘Public Class Account’ and ‘End Class’. Study the Account class and identify the public methods it provides. Design the form: i. Add appropriate VB controls on the Form for user input. ii. Add three buttons: Deposit, Withdraw and Exit, each with an appropriate name and style. Study the example program code given in Lecture 4 for bank account transaction and make sure you understand how it works and why. Implement the program: i. Declare an object of Account class named myAccount (before any methods). ii. On loading the form, create and initialize the object myAccount with a given amount of money and display the current balance on the form. iii. When the Deposit or Withdraw button is clicked, the balance of myAccount is updated accordingly and displayed on the form. iv. Clicking on the Exit button closes the program. Select File > Save All to save the project in your folder. Run the program and check if it works as expected. If not, find out why and fix it.
Session: Jan - June 2008 Subject Code: FSB23103
Page: 1 of 2
LAB 3 – CREATING AND USING VARIABLE Appendix Public Class Account Private balance As Double Public Sub New(ByVal iniAmount As Double) balance = iniAmount End Sub Public Sub Deposit(ByVal amount As Double) balance += amount End Sub Public Sub Withdraw(ByVal amount As Double) balance -= amount End Sub Public ReadOnly Property currentBalance() As Double Get Return balance End Get End Property End Class
Session: Jan - June 2008 Subject Code: FSB23103
Page: 2 of 2