' Exercise 4.11 Solution: WageCalculator.vb

Public Class WageCalculator

' handles Calculate Button's Click event

Private Sub calculateButton_Click(ByVal sender As System.Object,

ByVal e As System.EventArgs) Handles calculateButton.Click

' declare variables

Dim hours As Double

Dim wage As Double

Dim earnings As Double

Dim federalTaxes As Double

' assign values from user input

hours = hoursTextBox.Text

wage = wageTextBox.Text

' determine earnings

If hours <= 40 Then

' if less than or equal to 40 hours, regular wages

earnings = hours * wage

Else

' if over 40 hours, reglular wages for first 40

earnings = 40 * wage

' time and a half for the additional hours

earnings += (hours - 40) * (1.5 * wage)

End If

' assign the result to its corresponding Label

earningsResultLabel.Text = String.Format("{0:C}", earnings)

' assign federal taxes to the corresponding Label

federalTaxes = 0.15 * earnings

fwtResultLabel.Text = String.Format("{0:C}", federalTaxes)

' assign net pay to the corresponding Label

netResultLabel.Text = String.Format("{0:C}",

earnings - federalTaxes)

End Sub ' calculateButton_Click

' handles Clear Button's Click event

Private Sub clearButton_Click(ByVal sender As System.Object,

ByVal e As System.EventArgs) Handles clearButton.Click

' clear TextBoxes and output Labels

hoursTextBox.Text = String.Empty

wageTextBox.Text = String.Empty

earningsResultLabel.Text = String.Empty

fwtResultLabel.Text = String.Empty

netResultLabel.Text = String.Empty

wageTextBox.Focus() ' give this TextBox the focus

End Sub ' clearButton_Click

End Class ' WageCalculator

' **************************************************************************

' * (C) Copyright 1992-2011 by Deitel & Associates, Inc. and *

' * Pearson Education, Inc. All Rights Reserved. *

' * *

' * DISCLAIMER: The authors and publisher of this book have used their *

' * best efforts in preparing the book. These efforts include the *

' * development, research, and testing of the theories and programs *

' * to determine their effectiveness. The authors and publisher make *

' * no warranty of any kind, expressed or implied, with regard to these *

' * programs or to the documentation contained in these books. The authors *

' * and publisher shall not be liable in any event for incidental or *

' * consequential damages in connection with, or arising out of, the *

' * furnishing, performance, or use of these programs. *

' **************************************************************************