Write a VB program to calculate the wages based on different rates (Normal hours and Overtime rates).
Write a FUNCTION to calculate the wages based on the following condition:
-Normal Hours: RM 10 per hours
-Overtime: RM 15 per hours
NOTE: The function should pass in a value of hours as Double, and a value of type as String. The function should return the calculated amount of wages and return as a Double.
*set the Enabled properties of the Total Wages Text Box to False
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmCalculateWages
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.btnCalculate = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.txtHours = New System.Windows.Forms.TextBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.txtTotalWages = New System.Windows.Forms.TextBox()
Me.rbNormalHours = New System.Windows.Forms.RadioButton()
Me.rbOvertimeRates = New System.Windows.Forms.RadioButton()
Me.SuspendLayout()
'
'btnCalculate
'
Me.btnCalculate.Location = New System.Drawing.Point(107, 125)
Me.btnCalculate.Name = "btnCalculate"
Me.btnCalculate.Size = New System.Drawing.Size(100, 25)
Me.btnCalculate.TabIndex = 0
Me.btnCalculate.Text = "Calculate"
Me.btnCalculate.UseVisualStyleBackColor = True
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(14, 21)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(67, 13)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Enter hours: "
'
'txtHours
'
Me.txtHours.Location = New System.Drawing.Point(107, 18)
Me.txtHours.Name = "txtHours"
Me.txtHours.Size = New System.Drawing.Size(100, 20)
Me.txtHours.TabIndex = 2
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(14, 90)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(71, 13)
Me.Label2.TabIndex = 1
Me.Label2.Text = "Total Wages:"
'
'txtTotalWages
'
Me.txtTotalWages.Enabled = False
Me.txtTotalWages.Location = New System.Drawing.Point(107, 87)
Me.txtTotalWages.Name = "txtTotalWages"
Me.txtTotalWages.Size = New System.Drawing.Size(100, 20)
Me.txtTotalWages.TabIndex = 2
'
'rbNormalHours
'
Me.rbNormalHours.AutoSize = True
Me.rbNormalHours.Checked = True
Me.rbNormalHours.Location = New System.Drawing.Point(17, 54)
Me.rbNormalHours.Name = "rbNormalHours"
Me.rbNormalHours.Size = New System.Drawing.Size(87, 17)
Me.rbNormalHours.TabIndex = 3
Me.rbNormalHours.Text = "Normal hours"
Me.rbNormalHours.UseVisualStyleBackColor = True
'
'rbOvertimeRates
'
Me.rbOvertimeRates.AutoSize = True
Me.rbOvertimeRates.Location = New System.Drawing.Point(111, 54)
Me.rbOvertimeRates.Name = "rbOvertimeRates"
Me.rbOvertimeRates.Size = New System.Drawing.Size(93, 17)
Me.rbOvertimeRates.TabIndex = 3
Me.rbOvertimeRates.Text = "Overtime rates"
Me.rbOvertimeRates.UseVisualStyleBackColor = True
'
'frmCalculateWages
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(227, 169)
Me.Controls.Add(Me.rbOvertimeRates)
Me.Controls.Add(Me.rbNormalHours)
Me.Controls.Add(Me.txtTotalWages)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.txtHours)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btnCalculate)
Me.Name = "frmCalculateWages"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Calculate wages"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents btnCalculate As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents txtHours As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents txtTotalWages As System.Windows.Forms.TextBox
Friend WithEvents rbNormalHours As System.Windows.Forms.RadioButton
Friend WithEvents rbOvertimeRates As System.Windows.Forms.RadioButton
End Class
Public Class frmCalculateWages
''' <summary>
''' Write a FUNCTION to calculate the wages based on the following condition:
''' -Normal Hours: RM 10 per hours
''' -Overtime: RM 15 per hours
''' </summary>
''' <param name="hours"></param>
''' <param name="type"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function calculateWages(ByVal hours As Double, ByVal type As String) As Double
If (type = "Normal Hours") Then
Return 10 * hours
End If
Return 15 * hours
End Function
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim hours As Double
Double.TryParse(txtHours.Text, hours)
If rbNormalHours.Checked Then
txtTotalWages.Text = calculateWages(hours, "Normal Hours").ToString("C")
Else
txtTotalWages.Text = calculateWages(hours, "Overtime rates").ToString("C")
End If
End Sub
End Class
Comments