我正在進行工資計劃。第一個基礎類是獎勵,該類應包含2個公共屬性salesid和sales。 在類中包含一個默認構造函數和一個參數化構造函數。還包括一個getbonus方法(函數),它使用公式銷售計算銷售人員獎金* 0.05 創建派生類名爲Premiumbonus派生類getbonus mothod計算獎金如下sales0 .05 +(sales-2500)).01還包含此派生類中的默認和參數化構造函數。 如果銷售超過2500使用這個工資單程序沒有顯示正確的金額結果
我覺得我的數學是關閉有人可以請仔細檢查它嗎?我需要一些建議,並且我試圖調試並且getbonus好像一直保持0,不管我輸入了多少個數字,但是我在計算框中得到了結果。下面 是代碼
顯式的選項在 選項嚴格在 選項推斷關
' base class
Public Class Bonus
Public Property SalesId As String
Public Property Sales As Double
Public Sub New()
_Sales = 0
_SalesId = String.Empty
End Sub
Public Sub New(ByVal dblB As Double,
ByVal strId As String)
_Sales = dblB
_SalesId = strId
End Sub
Public Overridable Function GetBonus() As Double
' returns sales
Return _Sales * 0.05
End Function
End Class
' derived class
Public Class PremiumBonus
Inherits Bonus
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal dblB As Double,
ByVal strId As String)
MyBase.New(dblB, strId)
End Sub
Public Overrides Function GetBonus() As Double
Return MyBase.GetBonus + (Sales - 2500) * 0.01
End Function
End Class
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
' calculates and displays a bonus
Dim myBonus As New Bonus
Dim myPremiumBonus As New PremiumBonus
Dim Sales As Double
' if the sales are over $2500, instantiate a PremiumBonus object
' and then calculate the bonus
' otherwise, instantiate a Bonus object and then calculate the bonus
If Sales > 2500 Then
Double.TryParse(txtSales.Text, myBonus.Sales)
Sales = myBonus.GetBonus
Else
Double.TryParse(txtSales.Text, myPremiumBonus.Sales)
Sales = myPremiumBonus.GetBonus
End If
工藝的一個具體問題,如*當我進入X,結果是Y,但它應該爲Z *我們不是代碼檢查器,我們不提供建議。這是關於*答案* *問題*。參見[問] – Plutonix