Needing help with my CSIS 208 Assignment 8
Question
Needing help with my CSIS 208 Assignment 8:Write a Visual Basic program to implement the cash register in
the diagram below. The program should have a class called CashRegister that keeps track of the balance and allows deposits and withdrawals. The class should not permit a negative balance. If the user tries to subtract a number that would result in a negative balance, the system should produce a messagebox indicating that the transaction would result in a negative balance, which is not permitted.
Here’s what I have and the code doesn’t work….I can get it to allow me to enter the text but the add/subtract buttons don’t work. I”m using Visual Studio
Public Class Form1
Dim Cash As New CashRegister
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If txtBalance.Text = “” Then
txtBalance.Text = “0”
End If
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
txtBalance.Text = FormatCurrency(Cash.AddMethod(txtAmt.Text))
End Sub
Private Sub btnSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubtract.Click
txtBalance.Text = FormatCurrency(Cash.SubtractMethod(txtAmt.Text))
If txtBalance.Text MessageBox.Show(“Transaction would result in negative balance, which is not permitted!”)
txtBalance.Text = “0”
End If
End Sub
End Class
Class CashRegister
Public Balance As Integer
Public addAmt As Double
Public subAmt As Double
Public Property AddMethod(ByVal amount As String) As Double
Get
Return addAmt
End Get
Set(ByVal value As Double)
Dim x As Integer = amount
Dim y As Integer = amount
addAmt = x + y
End Set
End Property
Public Property SubtractMethod(ByVal amount As String) As Double
Get
Return subAmt
End Get
Set(ByVal value As Double)
Dim x As Integer = amount
Dim y As Integer = amount
subAmt = y – x
End Set
End Property
End Class
Thank you for your help