SlideShare a Scribd company logo
CSC139 Chapter 9 Lab Assignments (1)
Classes and Objects
Objectives
In this lab assignment, students will learn:
- How to design and define class
- How to create object
- How to define a tester program to test the object
Goals
In this lab assignment, students will demonstrate the abilities
to:
- Design and define class
- Create object
- Define a tester program to test the object
Grading
- Design and create a GUI (20 pts)
- Design and define class (40 pts)
- Define tester program (40 pts)
Develop a "
BankAccount
" windows form project, which will allow user to
- Enter amount of money to deposit, withdraw or move
- Deposit money in checking or savings account.
- Withdraw money from checking or savings account.
- Move money between checking account and saving account.
- View the new balance on the form after each transaction.
Here is sample input/output:
When start to run project, initial balances for both checking and
saving accounts ($1000.00) should be displayed on the form.
After deposit $500.00 to checking account.
After move $800.00 from saving to checking account.
If user attempts to withdraw $4000.00 from checking account at
this moment, a MessageBox should be displayed with an error
message.
Project specifications --------
1. This project should perform object-oriented programming.
Add a class file "Account.vb" to define class "Account", rename
"Form1.vb" file as "AccountTesterForm.vb" which will create
account object and test the object’s attributes and behaviors.
2.
This is the GUI for the bank. The amount of money need to be
entered from the textbox, each button represents a type of
transaction. The new balance will be displayed on the form after
each transaction.
Please use the same control names in order to use the tester
program code below.
balanceLabel
amountTextBox
moveStoCButton
withdrawSavingButton
depositSavingButton
moveCtoSButton
depositCheckingButton
withdrawCheckingButton
3.
Here is the definition of class Account, some codes are missing,
you may copy the code to your project in Visual Studio and
complete the missing code.
Public Class Account
Private savingBalance As Decimal 'instance variable for balance
in saving account
Private checkingBalance As Decimal 'instance variable for
balance in checking account
'constructor which initialize balances in both accounts to
1000.00
Public Sub New()
savingBalance = 1000.0
checkingBalance = 1000.0
End Sub
'property for savingBalance
Public Property Saving() As Double
Get
Return savingBalance
End Get
Set(ByVal value As Double)
If value < 0 Then
savingBalance = 0
Else
savingBalance = value
End If
End Set
End Property
'property for checkingBalance
Public Property Checking() As Double
'write your code here
End Property
'define how to deposit money to checking account
Public Sub depositChecking(ByVal amount As Decimal)
'write your code here
End Sub
'define how to deposit money to saving account
Public Sub depositSaving(ByVal amount As Decimal)
'write your code here
End Sub
'define how to withdraw money from checking account
Public Sub withdrawChecking(ByVal amount As Decimal)
If amount > Checking Then
Throw New ArgumentOutOfRangeException(
"Withdrawal amount must be less than or equal to balance.")
ElseIf amount <= 0D Then
Throw New ArgumentOutOfRangeException(
"Withrawal amount must be positive.")
End If
Checking -= amount
End Sub
'define how to withdraw money from saving account
Public Sub withdrawSaving(ByVal amount As Decimal)
'write your code here
End Sub
'define how to move money from checking to saving account
Public Sub moveMoneyCheckingtoSaving(ByVal amount As
Double)
'write your code here
End Sub
'define how to move money from saving to checking account
Public Sub moveMoneySavingtoChecking(ByVal amount As
Double)
'write your code here
End Sub
End Class
4.
Here is the code for accountTesterForm.vb, some codes are
missing, you may copy the code to your project in Visual Studio
and complete the missing code (
The header of event handler methods can NOT be copied, they
need to be created by double clicking the corresponding buttons
).
Option Strict On
Public Class AccountTesterForm
Dim account As New Account()
Private Sub AccountTesterForm_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
displayBalance()
End Sub
Private Sub DepositCheckingButton_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DepositCheckingButton.Click
Try
account.depositChecking(Convert.ToDecimal(AmountTextBox.
Text))
displayBalance()
Catch ex As ArgumentOutOfRangeException
MessageBox.Show("Deposit amount must be positive.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
AmountTextBox.Clear() ' clear the inputTextBox
AmountTextBox.Focus()
End Sub
Private Sub DepositSavingButton_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DepositSavingButton.Click
'write your code here
End Sub
Private Sub withdrawCheckingButton_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
withdrawCheckingButton.Click
'write your code here
End Sub
Private Sub withdrawSavingButton_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
withdrawSavingButton.Click
'write your code here
End Sub
Private Sub movectosButton_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
movectosButton.Click
'write your code here
End Sub
Private Sub moveStoCButton_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
moveStoCButton.Click
'write your code here
End Sub
Private Sub displayBalance()
balanceLabel.Text = "Checking balance: " &
String.Format("{0:C}", account.Checking) & vbCrLf & "Saving
balance: " & String.Format("{0:C}", account.Saving)
End Sub
End Class
Ad

More Related Content

Similar to CSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docx (17)

Dynamics ax 2012 workflow development
Dynamics ax 2012 workflow development Dynamics ax 2012 workflow development
Dynamics ax 2012 workflow development
Ahmed Farag
 
Write a banking program that simulates the operation of your local ba.docx
 Write a banking program that simulates the operation of your local ba.docx Write a banking program that simulates the operation of your local ba.docx
Write a banking program that simulates the operation of your local ba.docx
ajoy21
 
Cbse computer science (c++) class 12 board project bank managment system
Cbse computer science (c++)  class 12 board project  bank managment systemCbse computer science (c++)  class 12 board project  bank managment system
Cbse computer science (c++) class 12 board project bank managment system
pranoy_seenu
 
Cis 247 all i labs
Cis 247 all i labsCis 247 all i labs
Cis 247 all i labs
ccis224477
 
Itco 620 unit 5 project
Itco 620 unit 5 projectItco 620 unit 5 project
Itco 620 unit 5 project
comp274
 
Banks offer various types of accounts, such as savings, checking, cer.pdf
 Banks offer various types of accounts, such as savings, checking, cer.pdf Banks offer various types of accounts, such as savings, checking, cer.pdf
Banks offer various types of accounts, such as savings, checking, cer.pdf
akbsingh1313
 
SAP SD Training in Chennai
SAP SD Training in Chennai SAP SD Training in Chennai
SAP SD Training in Chennai
Thecreating Experts
 
Vbtutorial
VbtutorialVbtutorial
Vbtutorial
dhi her
 
Tang doanh thu quang cao di dong
Tang doanh thu quang cao di dongTang doanh thu quang cao di dong
Tang doanh thu quang cao di dong
Duc Canh Tran
 
PT1420 Decision Structures in Pseudocode and Visual Basic .docx
PT1420 Decision Structures in Pseudocode and Visual Basic .docxPT1420 Decision Structures in Pseudocode and Visual Basic .docx
PT1420 Decision Structures in Pseudocode and Visual Basic .docx
amrit47
 
Create chart of account
Create chart of accountCreate chart of account
Create chart of account
Hassan Fadl
 
Consider this C++ BankAccount class with the following public member.pdf
Consider this C++ BankAccount class with the following public member.pdfConsider this C++ BankAccount class with the following public member.pdf
Consider this C++ BankAccount class with the following public member.pdf
archigallery1298
 
Creating modeled views
Creating modeled viewsCreating modeled views
Creating modeled views
Emerson Carlos Rocha
 
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slidesC# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slides
Sami Mut
 
Tony Vitabile .Net Portfolio
Tony Vitabile .Net PortfolioTony Vitabile .Net Portfolio
Tony Vitabile .Net Portfolio
vitabile
 
Demo how to create visualforce page and custom controller via developer console
Demo how to create visualforce page and custom controller via developer consoleDemo how to create visualforce page and custom controller via developer console
Demo how to create visualforce page and custom controller via developer console
tuan vo
 
Project1 VB
Project1 VBProject1 VB
Project1 VB
sunmitraeducation
 
Dynamics ax 2012 workflow development
Dynamics ax 2012 workflow development Dynamics ax 2012 workflow development
Dynamics ax 2012 workflow development
Ahmed Farag
 
Write a banking program that simulates the operation of your local ba.docx
 Write a banking program that simulates the operation of your local ba.docx Write a banking program that simulates the operation of your local ba.docx
Write a banking program that simulates the operation of your local ba.docx
ajoy21
 
Cbse computer science (c++) class 12 board project bank managment system
Cbse computer science (c++)  class 12 board project  bank managment systemCbse computer science (c++)  class 12 board project  bank managment system
Cbse computer science (c++) class 12 board project bank managment system
pranoy_seenu
 
Cis 247 all i labs
Cis 247 all i labsCis 247 all i labs
Cis 247 all i labs
ccis224477
 
Itco 620 unit 5 project
Itco 620 unit 5 projectItco 620 unit 5 project
Itco 620 unit 5 project
comp274
 
Banks offer various types of accounts, such as savings, checking, cer.pdf
 Banks offer various types of accounts, such as savings, checking, cer.pdf Banks offer various types of accounts, such as savings, checking, cer.pdf
Banks offer various types of accounts, such as savings, checking, cer.pdf
akbsingh1313
 
Vbtutorial
VbtutorialVbtutorial
Vbtutorial
dhi her
 
Tang doanh thu quang cao di dong
Tang doanh thu quang cao di dongTang doanh thu quang cao di dong
Tang doanh thu quang cao di dong
Duc Canh Tran
 
PT1420 Decision Structures in Pseudocode and Visual Basic .docx
PT1420 Decision Structures in Pseudocode and Visual Basic .docxPT1420 Decision Structures in Pseudocode and Visual Basic .docx
PT1420 Decision Structures in Pseudocode and Visual Basic .docx
amrit47
 
Create chart of account
Create chart of accountCreate chart of account
Create chart of account
Hassan Fadl
 
Consider this C++ BankAccount class with the following public member.pdf
Consider this C++ BankAccount class with the following public member.pdfConsider this C++ BankAccount class with the following public member.pdf
Consider this C++ BankAccount class with the following public member.pdf
archigallery1298
 
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slidesC# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slides
Sami Mut
 
Tony Vitabile .Net Portfolio
Tony Vitabile .Net PortfolioTony Vitabile .Net Portfolio
Tony Vitabile .Net Portfolio
vitabile
 
Demo how to create visualforce page and custom controller via developer console
Demo how to create visualforce page and custom controller via developer consoleDemo how to create visualforce page and custom controller via developer console
Demo how to create visualforce page and custom controller via developer console
tuan vo
 

More from ruthannemcmullen (20)

Describe how an attacker could use a sniffer in conjunction with a T.docx
Describe how an attacker could use a sniffer in conjunction with a T.docxDescribe how an attacker could use a sniffer in conjunction with a T.docx
Describe how an attacker could use a sniffer in conjunction with a T.docx
ruthannemcmullen
 
Describe a specific workplace conflict situation involving the compe.docx
Describe a specific workplace conflict situation involving the compe.docxDescribe a specific workplace conflict situation involving the compe.docx
Describe a specific workplace conflict situation involving the compe.docx
ruthannemcmullen
 
Describe common biases in decision making.Explain the roles of emo.docx
Describe common biases in decision making.Explain the roles of emo.docxDescribe common biases in decision making.Explain the roles of emo.docx
Describe common biases in decision making.Explain the roles of emo.docx
ruthannemcmullen
 
Describe an example of a television program that you believe clearly.docx
Describe an example of a television program that you believe clearly.docxDescribe an example of a television program that you believe clearly.docx
Describe an example of a television program that you believe clearly.docx
ruthannemcmullen
 
Describe Abell’s three-dimensional business-definition model and exp.docx
Describe Abell’s three-dimensional business-definition model and exp.docxDescribe Abell’s three-dimensional business-definition model and exp.docx
Describe Abell’s three-dimensional business-definition model and exp.docx
ruthannemcmullen
 
Describe an example of a contract that you or someone you know enter.docx
Describe an example of a contract that you or someone you know enter.docxDescribe an example of a contract that you or someone you know enter.docx
Describe an example of a contract that you or someone you know enter.docx
ruthannemcmullen
 
Denial & Deception – Week 7Select one of the ‘Questions to Pon.docx
Denial & Deception – Week 7Select one of the ‘Questions to Pon.docxDenial & Deception – Week 7Select one of the ‘Questions to Pon.docx
Denial & Deception – Week 7Select one of the ‘Questions to Pon.docx
ruthannemcmullen
 
Denial-of-service attacks are a common method to bring down an organ.docx
Denial-of-service attacks are a common method to bring down an organ.docxDenial-of-service attacks are a common method to bring down an organ.docx
Denial-of-service attacks are a common method to bring down an organ.docx
ruthannemcmullen
 
Demonstration of core knowledgeThe following section demonstrate.docx
Demonstration of core knowledgeThe following section demonstrate.docxDemonstration of core knowledgeThe following section demonstrate.docx
Demonstration of core knowledgeThe following section demonstrate.docx
ruthannemcmullen
 
Describe at least five ways IT has helped change HR. What are the .docx
Describe at least five ways IT has helped change HR. What are the .docxDescribe at least five ways IT has helped change HR. What are the .docx
Describe at least five ways IT has helped change HR. What are the .docx
ruthannemcmullen
 
Dental offices, which most people consider environmentally benign .docx
Dental offices, which most people consider environmentally benign .docxDental offices, which most people consider environmentally benign .docx
Dental offices, which most people consider environmentally benign .docx
ruthannemcmullen
 
Democracies Around the WorldThe United States does not have a .docx
Democracies Around the WorldThe United States does not have a .docxDemocracies Around the WorldThe United States does not have a .docx
Democracies Around the WorldThe United States does not have a .docx
ruthannemcmullen
 
Deliverable Length  500-750 wordsOutline the major theories of .docx
Deliverable Length  500-750 wordsOutline the major theories of .docxDeliverable Length  500-750 wordsOutline the major theories of .docx
Deliverable Length  500-750 wordsOutline the major theories of .docx
ruthannemcmullen
 
Deliverable Length  A one-page letter to employeesLetter to E.docx
Deliverable Length  A one-page letter to employeesLetter to E.docxDeliverable Length  A one-page letter to employeesLetter to E.docx
Deliverable Length  A one-page letter to employeesLetter to E.docx
ruthannemcmullen
 
Deliverable Length  400 - 600 wordsSummative Discussion Boa.docx
Deliverable Length  400 - 600 wordsSummative Discussion Boa.docxDeliverable Length  400 - 600 wordsSummative Discussion Boa.docx
Deliverable Length  400 - 600 wordsSummative Discussion Boa.docx
ruthannemcmullen
 
Deliverable Length800 - 1000 wordsDetailsWeekly tasks or ass.docx
Deliverable Length800 - 1000 wordsDetailsWeekly tasks or ass.docxDeliverable Length800 - 1000 wordsDetailsWeekly tasks or ass.docx
Deliverable Length800 - 1000 wordsDetailsWeekly tasks or ass.docx
ruthannemcmullen
 
Deliverable Length  2-4 pagesConsider the facts of the follow.docx
Deliverable Length  2-4 pagesConsider the facts of the follow.docxDeliverable Length  2-4 pagesConsider the facts of the follow.docx
Deliverable Length  2-4 pagesConsider the facts of the follow.docx
ruthannemcmullen
 
Deliverable Length  5 slides (body of presentation), with in-depth .docx
Deliverable Length  5 slides (body of presentation), with in-depth .docxDeliverable Length  5 slides (body of presentation), with in-depth .docx
Deliverable Length  5 slides (body of presentation), with in-depth .docx
ruthannemcmullen
 
Deliverable Length800–1,000 words, including a completed table.docx
Deliverable Length800–1,000 words, including a completed table.docxDeliverable Length800–1,000 words, including a completed table.docx
Deliverable Length800–1,000 words, including a completed table.docx
ruthannemcmullen
 
Deliverable Length  1-2 pagesSociologists cite the weakening .docx
Deliverable Length  1-2 pagesSociologists cite the weakening .docxDeliverable Length  1-2 pagesSociologists cite the weakening .docx
Deliverable Length  1-2 pagesSociologists cite the weakening .docx
ruthannemcmullen
 
Describe how an attacker could use a sniffer in conjunction with a T.docx
Describe how an attacker could use a sniffer in conjunction with a T.docxDescribe how an attacker could use a sniffer in conjunction with a T.docx
Describe how an attacker could use a sniffer in conjunction with a T.docx
ruthannemcmullen
 
Describe a specific workplace conflict situation involving the compe.docx
Describe a specific workplace conflict situation involving the compe.docxDescribe a specific workplace conflict situation involving the compe.docx
Describe a specific workplace conflict situation involving the compe.docx
ruthannemcmullen
 
Describe common biases in decision making.Explain the roles of emo.docx
Describe common biases in decision making.Explain the roles of emo.docxDescribe common biases in decision making.Explain the roles of emo.docx
Describe common biases in decision making.Explain the roles of emo.docx
ruthannemcmullen
 
Describe an example of a television program that you believe clearly.docx
Describe an example of a television program that you believe clearly.docxDescribe an example of a television program that you believe clearly.docx
Describe an example of a television program that you believe clearly.docx
ruthannemcmullen
 
Describe Abell’s three-dimensional business-definition model and exp.docx
Describe Abell’s three-dimensional business-definition model and exp.docxDescribe Abell’s three-dimensional business-definition model and exp.docx
Describe Abell’s three-dimensional business-definition model and exp.docx
ruthannemcmullen
 
Describe an example of a contract that you or someone you know enter.docx
Describe an example of a contract that you or someone you know enter.docxDescribe an example of a contract that you or someone you know enter.docx
Describe an example of a contract that you or someone you know enter.docx
ruthannemcmullen
 
Denial & Deception – Week 7Select one of the ‘Questions to Pon.docx
Denial & Deception – Week 7Select one of the ‘Questions to Pon.docxDenial & Deception – Week 7Select one of the ‘Questions to Pon.docx
Denial & Deception – Week 7Select one of the ‘Questions to Pon.docx
ruthannemcmullen
 
Denial-of-service attacks are a common method to bring down an organ.docx
Denial-of-service attacks are a common method to bring down an organ.docxDenial-of-service attacks are a common method to bring down an organ.docx
Denial-of-service attacks are a common method to bring down an organ.docx
ruthannemcmullen
 
Demonstration of core knowledgeThe following section demonstrate.docx
Demonstration of core knowledgeThe following section demonstrate.docxDemonstration of core knowledgeThe following section demonstrate.docx
Demonstration of core knowledgeThe following section demonstrate.docx
ruthannemcmullen
 
Describe at least five ways IT has helped change HR. What are the .docx
Describe at least five ways IT has helped change HR. What are the .docxDescribe at least five ways IT has helped change HR. What are the .docx
Describe at least five ways IT has helped change HR. What are the .docx
ruthannemcmullen
 
Dental offices, which most people consider environmentally benign .docx
Dental offices, which most people consider environmentally benign .docxDental offices, which most people consider environmentally benign .docx
Dental offices, which most people consider environmentally benign .docx
ruthannemcmullen
 
Democracies Around the WorldThe United States does not have a .docx
Democracies Around the WorldThe United States does not have a .docxDemocracies Around the WorldThe United States does not have a .docx
Democracies Around the WorldThe United States does not have a .docx
ruthannemcmullen
 
Deliverable Length  500-750 wordsOutline the major theories of .docx
Deliverable Length  500-750 wordsOutline the major theories of .docxDeliverable Length  500-750 wordsOutline the major theories of .docx
Deliverable Length  500-750 wordsOutline the major theories of .docx
ruthannemcmullen
 
Deliverable Length  A one-page letter to employeesLetter to E.docx
Deliverable Length  A one-page letter to employeesLetter to E.docxDeliverable Length  A one-page letter to employeesLetter to E.docx
Deliverable Length  A one-page letter to employeesLetter to E.docx
ruthannemcmullen
 
Deliverable Length  400 - 600 wordsSummative Discussion Boa.docx
Deliverable Length  400 - 600 wordsSummative Discussion Boa.docxDeliverable Length  400 - 600 wordsSummative Discussion Boa.docx
Deliverable Length  400 - 600 wordsSummative Discussion Boa.docx
ruthannemcmullen
 
Deliverable Length800 - 1000 wordsDetailsWeekly tasks or ass.docx
Deliverable Length800 - 1000 wordsDetailsWeekly tasks or ass.docxDeliverable Length800 - 1000 wordsDetailsWeekly tasks or ass.docx
Deliverable Length800 - 1000 wordsDetailsWeekly tasks or ass.docx
ruthannemcmullen
 
Deliverable Length  2-4 pagesConsider the facts of the follow.docx
Deliverable Length  2-4 pagesConsider the facts of the follow.docxDeliverable Length  2-4 pagesConsider the facts of the follow.docx
Deliverable Length  2-4 pagesConsider the facts of the follow.docx
ruthannemcmullen
 
Deliverable Length  5 slides (body of presentation), with in-depth .docx
Deliverable Length  5 slides (body of presentation), with in-depth .docxDeliverable Length  5 slides (body of presentation), with in-depth .docx
Deliverable Length  5 slides (body of presentation), with in-depth .docx
ruthannemcmullen
 
Deliverable Length800–1,000 words, including a completed table.docx
Deliverable Length800–1,000 words, including a completed table.docxDeliverable Length800–1,000 words, including a completed table.docx
Deliverable Length800–1,000 words, including a completed table.docx
ruthannemcmullen
 
Deliverable Length  1-2 pagesSociologists cite the weakening .docx
Deliverable Length  1-2 pagesSociologists cite the weakening .docxDeliverable Length  1-2 pagesSociologists cite the weakening .docx
Deliverable Length  1-2 pagesSociologists cite the weakening .docx
ruthannemcmullen
 
Ad

Recently uploaded (20)

How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Ad

CSC139 Chapter 9 Lab Assignments (1) Classes and Obj.docx

  • 1. CSC139 Chapter 9 Lab Assignments (1) Classes and Objects Objectives In this lab assignment, students will learn: - How to design and define class - How to create object - How to define a tester program to test the object Goals
  • 2. In this lab assignment, students will demonstrate the abilities to: - Design and define class - Create object - Define a tester program to test the object Grading - Design and create a GUI (20 pts) - Design and define class (40 pts) - Define tester program (40 pts)
  • 3. Develop a " BankAccount " windows form project, which will allow user to - Enter amount of money to deposit, withdraw or move - Deposit money in checking or savings account. - Withdraw money from checking or savings account. - Move money between checking account and saving account. - View the new balance on the form after each transaction. Here is sample input/output: When start to run project, initial balances for both checking and saving accounts ($1000.00) should be displayed on the form.
  • 4. After deposit $500.00 to checking account. After move $800.00 from saving to checking account. If user attempts to withdraw $4000.00 from checking account at this moment, a MessageBox should be displayed with an error message. Project specifications -------- 1. This project should perform object-oriented programming. Add a class file "Account.vb" to define class "Account", rename "Form1.vb" file as "AccountTesterForm.vb" which will create account object and test the object’s attributes and behaviors.
  • 5. 2. This is the GUI for the bank. The amount of money need to be entered from the textbox, each button represents a type of transaction. The new balance will be displayed on the form after each transaction. Please use the same control names in order to use the tester program code below. balanceLabel amountTextBox moveStoCButton withdrawSavingButton depositSavingButton
  • 6. moveCtoSButton depositCheckingButton withdrawCheckingButton 3. Here is the definition of class Account, some codes are missing, you may copy the code to your project in Visual Studio and complete the missing code. Public Class Account Private savingBalance As Decimal 'instance variable for balance in saving account Private checkingBalance As Decimal 'instance variable for balance in checking account
  • 7. 'constructor which initialize balances in both accounts to 1000.00 Public Sub New() savingBalance = 1000.0 checkingBalance = 1000.0 End Sub 'property for savingBalance Public Property Saving() As Double Get
  • 8. Return savingBalance End Get Set(ByVal value As Double) If value < 0 Then savingBalance = 0 Else savingBalance = value End If End Set
  • 9. End Property 'property for checkingBalance Public Property Checking() As Double 'write your code here End Property 'define how to deposit money to checking account Public Sub depositChecking(ByVal amount As Decimal) 'write your code here End Sub
  • 10. 'define how to deposit money to saving account Public Sub depositSaving(ByVal amount As Decimal) 'write your code here End Sub 'define how to withdraw money from checking account Public Sub withdrawChecking(ByVal amount As Decimal) If amount > Checking Then Throw New ArgumentOutOfRangeException( "Withdrawal amount must be less than or equal to balance.")
  • 11. ElseIf amount <= 0D Then Throw New ArgumentOutOfRangeException( "Withrawal amount must be positive.") End If Checking -= amount End Sub 'define how to withdraw money from saving account Public Sub withdrawSaving(ByVal amount As Decimal) 'write your code here
  • 12. End Sub 'define how to move money from checking to saving account Public Sub moveMoneyCheckingtoSaving(ByVal amount As Double) 'write your code here End Sub 'define how to move money from saving to checking account Public Sub moveMoneySavingtoChecking(ByVal amount As Double) 'write your code here End Sub
  • 13. End Class 4. Here is the code for accountTesterForm.vb, some codes are missing, you may copy the code to your project in Visual Studio and complete the missing code ( The header of event handler methods can NOT be copied, they need to be created by double clicking the corresponding buttons ). Option Strict On Public Class AccountTesterForm Dim account As New Account() Private Sub AccountTesterForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
  • 14. MyBase.Load displayBalance() End Sub Private Sub DepositCheckingButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DepositCheckingButton.Click Try account.depositChecking(Convert.ToDecimal(AmountTextBox. Text)) displayBalance() Catch ex As ArgumentOutOfRangeException MessageBox.Show("Deposit amount must be positive.",
  • 15. "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try AmountTextBox.Clear() ' clear the inputTextBox AmountTextBox.Focus() End Sub Private Sub DepositSavingButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DepositSavingButton.Click 'write your code here
  • 16. End Sub Private Sub withdrawCheckingButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles withdrawCheckingButton.Click 'write your code here End Sub Private Sub withdrawSavingButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles withdrawSavingButton.Click 'write your code here
  • 17. End Sub Private Sub movectosButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movectosButton.Click 'write your code here End Sub Private Sub moveStoCButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles moveStoCButton.Click 'write your code here
  • 18. End Sub Private Sub displayBalance() balanceLabel.Text = "Checking balance: " & String.Format("{0:C}", account.Checking) & vbCrLf & "Saving balance: " & String.Format("{0:C}", account.Saving) End Sub End Class