SlideShare a Scribd company logo
1 of 18
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

More Related Content

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

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.docxajoy21
 
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 systempranoy_seenu
 
Cis 247 all i labs
Cis 247 all i labsCis 247 all i labs
Cis 247 all i labsccis224477
 
Itco 620 unit 5 project
Itco 620 unit 5 projectItco 620 unit 5 project
Itco 620 unit 5 projectcomp274
 
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.pdfakbsingh1313
 
Vbtutorial
VbtutorialVbtutorial
Vbtutorialdhi 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 dongDuc 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 .docxamrit47
 
Create chart of account
Create chart of accountCreate chart of account
Create chart of accountHassan 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.pdfarchigallery1298
 
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-slidesSami Mut
 
Tony Vitabile .Net Portfolio
Tony Vitabile .Net PortfolioTony Vitabile .Net Portfolio
Tony Vitabile .Net Portfoliovitabile
 
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 consoletuan vo
 

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
 
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
 
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
 
Cis 247 all i labs
Cis 247 all i labsCis 247 all i labs
Cis 247 all i labs
 
Itco 620 unit 5 project
Itco 620 unit 5 projectItco 620 unit 5 project
Itco 620 unit 5 project
 
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
 
SAP SD Training in Chennai
SAP SD Training in Chennai SAP SD Training in Chennai
SAP SD Training in Chennai
 
Vbtutorial
VbtutorialVbtutorial
Vbtutorial
 
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
 
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
 
Create chart of account
Create chart of accountCreate chart of account
Create chart of account
 
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
 
Creating modeled views
Creating modeled viewsCreating modeled views
Creating modeled views
 
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
 
Tony Vitabile .Net Portfolio
Tony Vitabile .Net PortfolioTony Vitabile .Net Portfolio
Tony Vitabile .Net Portfolio
 
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
 
Project1 VB
Project1 VBProject1 VB
Project1 VB
 

More from 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.docxruthannemcmullen
 
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.docxruthannemcmullen
 
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.docxruthannemcmullen
 
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.docxruthannemcmullen
 
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.docxruthannemcmullen
 
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.docxruthannemcmullen
 
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.docxruthannemcmullen
 
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.docxruthannemcmullen
 
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.docxruthannemcmullen
 
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 .docxruthannemcmullen
 
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 .docxruthannemcmullen
 
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 .docxruthannemcmullen
 
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 .docxruthannemcmullen
 
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.docxruthannemcmullen
 
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.docxruthannemcmullen
 
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.docxruthannemcmullen
 
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.docxruthannemcmullen
 
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 .docxruthannemcmullen
 
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.docxruthannemcmullen
 
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 .docxruthannemcmullen
 

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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 

Recently uploaded

social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Recently uploaded (20)

social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

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