How to calculate average with only one input at a time?

  • Thread starter Thread starter Dslotegraaf
  • Start date Start date
D

Dslotegraaf

Guest
Hey So I'm currently making a program for employees pay. Its a wpf form using visual basic code.

So i currently have a form that has a textbox to enter employees name and a textbox to enter employees messages sent. Then I have a label for total pay for one employee then a label for total pay for all employees and then the average for all employees.

So my question is how do I calculate the average and total pay for the employees when I can only enter one at a time. Or is that even possiblee? I've ben stuck for a while and honestly dont know where to begin.

I started with making a do while loop and having a variable starting at zero or whatever thats called. But I dont really understand how it works to be honest.

Can anyone help?

Option Strict On
Class MainWindow
'PieceworkWorker.vb
' Title: IncInc Payroll(Piecework)
'Last Modified : September 13 2019
' Written By: Deanna Slotegraaf
'Adapted from PieceworkWorker by Kyle Chapman, September 2019

'This Is a class representing individual worker objects. Each stores
'their own name And number Of messages And the Class methods allow For
'calculation of the worker's pay and for updating of shared summary
'values. Name And messages are received as strings.
'This Is being used as part of a piecework payroll application.

'This Is currently incomplete; note the four comment blocks
'below that begin With "TO DO"

Public Class pieceworkworker

#Region "variable declarations"

' instance variables
Public employeename As String
Private employeemessages As Integer
Private employeepay As Decimal

Private isvalid As Boolean = True

' shared class variables
Private Shared overallnumberofemployees As Integer
Private Shared overallmessages As Integer
Private Shared overallpayroll As Decimal

#End Region

#Region "constructors"

''' <summary>
''' pieceworkworker constructor: accepts a worker's name and number of
''' messages, sets and calculates values as appropriate.
''' </summary>
''' <param name="namevalue">a worker's name</param>
''' <param name="messagesvalue">a worker's number of messages sent</param>
Friend Sub New(ByVal namevalue As String, messagesvalue As String)

' validate and set the worker's name
Me.name = namevalue
' validate and set the worker's number of messages
Me.messages = messagesvalue
' calculcate the worker's pay and update all summary values
findpay()

End Sub

''' <summary>
''' pieceworkworker constructor: empty constructor used strictly for
''' inheritance and instantiation
''' </summary>
Friend Sub New()

End Sub

#End Region

#Region "class methods"

''' <summary>
''' currently called in the constructor, the findpay() method is
''' used to calculate a worker's pay using threshold values to
''' change how much a worker is paid per message. this also updates
''' all summary values.
''' </summary>
'''
Private Sub findpay()

If (employeemessages >= 1 And employeemessages <= 2499) Then
employeepay = CDec(employeemessages * 0.018)

End If

If (employeemessages >= 2500 And employeemessages <= 4999) Then
employeepay = CDec(employeemessages * 0.024)
End If

If (employeemessages >= 5000 And employeemessages <= 7499) Then
employeepay = CDec(employeemessages * 0.03)
End If

If (employeemessages >= 7500 And employeemessages <= 10000) Then
employeepay = CDec(employeemessages * 0.035)
End If

If (employeemessages > 10000) Then
employeepay = CDec(employeemessages * 0.04)
End If


End Sub


#End Region

#Region "property procedures"

''' <summary>
''' gets and sets a worker's name
''' </summary>
''' <returns>an employee's name</returns>
Friend Property name() As String
Get
Return employeename
End Get
Set(namevalue As String)
If (String.IsNullOrEmpty(employeename)) Then
MessageBox.Show("error! must enter a name")
Else
findpay()

End If

employeename = namevalue

End Set
End Property

''' <summary>
''' gets and sets the number of messages sent by a worker
''' </summary>
''' <returns>an employee's number of messages</returns>
Friend Property messages() As String
Get
Return employeemessages.ToString()
End Get
Set(messagesvalue As String)

If employeemessages > 0 Then
findpay()
Else
MessageBox.Show("error! number must be a positive number")
End If

employeemessages = CInt(messagesvalue) ' this line is dangerous and should probably never appear in your code. can you explain why? post about it on the q&a board and i'll give you a stock.

End Set
End Property

''' <summary>
''' pay(): gets the worker's pay
''' </summary>
''' <returns>a worker's pay</returns>
Friend ReadOnly Property pay() As Decimal
Get
Return employeepay
End Get
End Property
''' <summary>
''' totalpay(): gets the overall total pay among all workers
''' </summary>
''' <returns>the overall total pay among all workers</returns>
Friend Shared ReadOnly Property totalpay() As Decimal
Get
Return overallpayroll
End Get
End Property
''' <summary>
''' gets the overall number of workers
''' </summary>
''' <returns>the overall number of workers</returns>
Friend Shared ReadOnly Property totalworkers() As Integer
Get
Return overallnumberofemployees
End Get
End Property
''' <summary>
''' gets the overall number of messages sent
''' </summary>
''' <returns>the overall number of messages sent</returns>
Friend Shared ReadOnly Property totalmessages() As Integer
Get
Return overallmessages
End Get
End Property
''' <summary>
''' calculates and returns an average pay among all workers
''' </summary>
''' <returns>the average pay among all workers</returns>
Friend Shared ReadOnly Property averagepay() As Decimal
Get
Dim messages As Integer = 0
Do While (messages < 10)
messages = messages + 1
Loop

End Get
End Property

#End Region

End Class

Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim employeemessages As Integer

employeemessages.findpay(lblTotalPay)

End Sub

End Class

My code ^

Continue reading...
 
Back
Top