我将提供附件表格和代码(我希望这完全是完整的)。因为我是新手,所以我整天都在挣扎。自从我使用VB以来,一直都是。感谢您提供任何帮助或指导。
这些类应该是只读的。类属性是:
•利息:持有当期所赚取的利息。 ReadOnly,(dblInterest)
•交易:持有的数量 本期交易。只读。使用e intTrans + = 1。
需要的方法:计算利息,提款,存款。显然,第一步是获得利率输入。我认为它应该在带有输入框的form_load事件中。
1)允许存款
2)允许提款
3)计算我假设的利率(dblInterestEarned = dblBalance *(dblIntRate / 12))
4)随时报告当前的交易数量 - intTrans + = 1。并明显退出
*编辑我只是觉得我搞得很糟糕,并且比以前更难。太累了我道歉。正确的方向迈出了任何一步,我今天想明白这一点***
Public Class Class1
'Create member variables for properties
Private dblBalance As Double
Private dblIntRate As Double
Private dblInterest As Double
Private intTrans As Integer
Private dblMakeWithdrawal As Double
Private dblMakeDeposit As Double
Private dblInterestEarned As Double
'Create property procedures
Public Property Balance As Double
Get
Return dblBalance
End Get
Set(value As Double)
dblBalance = value
End Set
End Property
Public Property IntRate As Double
Get
Return dblIntRate
End Get
Set(value As Double)
dblIntRate = value
End Set
End Property
Public Property InterestTotal As Double
Get
Return InterestTotal
End Get
Set(value As Double)
InterestTotal = value '''''''*expression recursively calls property interest total error
End Set
End Property
''trying to
'''calculate the amount of interest for the current period,
''' stores this value in the Interest property, and adds it to the Balance property.
Public Sub addInterest(ByVal addInterest As Integer)
dblInterestEarned = dblBalance * (dblIntRate / 12)
End Sub
''trying to add deposit
Public Sub addDeposit(ByVal addDeposit As Double)
dblMakeDeposit += addDeposit
End Sub
'''''to withdraw
Public Sub subtractWithdrawl(ByVal subtractWithdrawal As Double)
If dblMakeWithdrawal >= subtractWith() Then
dblMakeWithdrawal -= subtractWith()
Else
MessageBox.Show("No sufficient balance")
End If
End Sub
Private Function subtractWith() As Double
Throw New NotImplementedException
End Function
End Class
Imports System.IO
Public Class Form1
Dim dblMakeWithdrawal As Double
Private Sub btnDeposit_Click(sender As Object, e As EventArgs) Handles btnDeposit.Click
Dim dblMakeDeposit As Double
'''''how to capture inputs from the form load??
'Add Deposit
dblMakeDeposit = CDbl(InputBox("Please enter deposit if you have any"))
End Sub
Private Sub btnWithdraw_Click(sender As Object, e As EventArgs) Handles btnWithdraw.Click
Dim dblBalance As Integer
dblMakeWithdrawal = CDbl(InputBox("Please enter an amount to withdraw")
If dblBalance <= 0 Then
MessageBox.Show("Insufficient funds")
End If
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'''This is where to put the input box when the form loads?
MessageBox.Show"Please enter current interest")
''how to store?
End Sub
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
Dim dblInterTrans As Integer
dblInterest = dblintTrans+=1.
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Function dblintTrans() As Object
Throw New NotImplementedException
End Function
End Class
答案 0 :(得分:1)
这是一个修复:
Private dblInterest As Double
'...
Public Property InterestTotal As Double
Get
Return InterestTotal
End Get
Set(value As Double)
InterestTotal = value
'expression recursively calls property interest total error
End Set
End Property
当然它是recurses:InterestTotal
是属性的名称,所以当你尝试在Getter中返回它时,它会调用Getter来调用Getter,它与Setter相同。
你可能打算做其他人做的事情,使用backing field
:
Get
Return dblInterest
End Get
Set(value As Double)
dblInterest = value
End Set
但还有更多。如果您使用VS2010 +,您只需要:
Public Property InterestTotal As Double
这称为自动实现的属性。使用它们,VS / VB会创建一个名为_InterestTotal
的隐藏后备字段,并为您进行获取和设置。最后,如果这是钱,Decimal
可能是更好的数据类型。