a)I am working on a payroll program The first base class is bonus the class should contain 2 public properties salesid and sales.
Include a default constructor and a parameeterized constructor in the class.Also include a a getbonus method(function) that calculates a salespersons bonus using the formula sales*0.05

b) create a derived class named Premiumbonus the derived clas getbonus mothod calculate the bonus as follows sales0.05 +(sales-2500)).01 also include a default and parameterized constructorin this derived class.
if the sales is over 2500 use this

I feel like my math is off and I need some suggestions and also i tried to debug and getbonus seems like it stays on 0 no matter what number i put but I get results in the calculated box.
below is the code

Option Explicit On
Option Strict On
Option Infer Off

' 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

Edited 1 Year Ago by karodhill

If Sales > 2500 Then

How could you compair Sales variable without assigning any value to it. Everytime it can give you wrong result.
From my opinion the comparision would be

If Val(txtSales.Text) > 2500 Then

Hope it can help you.

I cant assign a variable to sales because it can be any value the user types in
but ill try it this way

Edited 1 Year Ago by karodhill

i fixed it i had the bonuses switched around in the wrong spots

This question has already been answered. Start a new discussion instead.