2015-04-25 85 views
-2

我正在進行工資計劃。第一個基礎類是獎勵,該類應包含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 
+0

工藝的一個具體問題,如*當我進入X,結果是Y,但它應該爲Z *我們不是代碼檢查器,我們不提供建議。這是關於*答案* *問題*。參見[問] – Plutonix

回答

0

感謝反正我固定它我有獎金在錯誤的地點

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 Val(txtSales.Text) > 2500 Then 
     Double.TryParse(txtSales.Text, myPremiumBonus.Sales) 
     Sales = myPremiumBonus.GetBonus 

    Else 
     Double.TryParse(txtSales.Text, myBonus.Sales) 
     Sales = myBonus.GetBonus() 
    End If 
0

根據您的標題:

薪酬方案顯示不正確的量導致

和部分描述:

getbonus好像它停留在0無論我穿什麼號碼,但我得到的結果在計算箱

我敢肯定你的問題是「我的輸出爲零,無論輸入的。什麼是錯的「


我在你的代碼中看到:

Dim Sales As Double 
If Sales > 2500 Then 
    Double.TryParse(txtSales.Text, myBonus.Sales) 
    Sales = myBonus.GetBonus 

你或許應該看看與之前的評估它的值填充Sales,並且它可能是一個好主意,不要使用相同的在許多地方變量名,因爲它使你的代碼更難以閱讀您可以嘗試這樣的事情:

Dim myNewBonus As Double 
Dim Sales As Double 
Double.TryParse(txtSales.Text, Sales) 
If Sales > 2500 Then 
    myBonus.Sales = Sales 
    myNewBonus = myBonus.GetBonus() 

任何如果還是失敗,請嘗試使用調試器,或在LEA ST的一些戰略地位MessageBox.Show(someValueIShouldCheck.ToString)