Public Class Form1 'Created by Zeki Ozyilmaz for CST 112 MIDTERM FALL 2008 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BRegpay.Click '"total up the number of hours and calculate the pay" 'Step0. Declarations Dim mon, tue, wed, thu, fri, x, y, payrate As Double 'Step1. Input mon = InputMon() tue = InputTue() wed = InputWed() thu = InputThur() fri = InputFri() payrate = Inputrate() 'Step2. Process x = payhour(mon, tue, wed, thu, fri) y = payamount(mon, tue, wed, thu, fri, x, payrate) 'Step3. Output Outputreg(x, y) End Sub Function InputMon() 'Gets the value of Monday Dim x As Double = TMon.Text Return Val(x) End Function Function InputTue() 'Gets the value of Tuesday Dim x As Double = TTues.Text Return Val(x) End Function Function InputWed() ' Gets the value of Wednesday Dim x As Double = TWed.Text Return Val(x) End Function Function InputThur() ' Gets the value of Thursday Dim x As Double = TThur.Text Return Val(x) End Function Function InputFri() ' Gets the value of Friday Dim x As Double = TFri.Text Return Val(x) End Function Function Inputrate() 'Gets the rate of pay per hour Dim x As Double = TRate.Text Return Val(x) End Function Function payhour(ByVal mon As Double, ByVal tue As Double, ByVal wed As Double, ByVal thu As Double, ByVal fri As Double) 'total up the number of hours and calculate the pay Dim x As Double x = Val(mon) + Val(tue) + Val(wed) + Val(thu) + Val(fri) Return x End Function Function payamount(ByVal mon As Double, ByVal tue As Double, ByVal wed As Double, ByVal thu As Double, ByVal fri As Double, ByVal x As Double, ByVal payrate As Double) 'Calculates pay Dim amount As Double If x >= 40 Then amount = ((x - 40) * 1.5 * payrate) + (40 * payrate) Else amount = payrate * x End If Return amount End Function Sub outputreg(ByVal x As Double, ByVal y As Double) 'Outputs pay With LOutput.Items .Add("The total numbers of hours worked is " & x) .Add("The total pay you get is " & y) End With End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BHoliday.Click '"if the number of hours worked on Monday was zero, then adds eight (8) paid hours for Monday " 'Step0. Declarations Dim mon, tue, wed, thu, fri, x, y, payrate As Double 'Step1. Input mon = InputMon() tue = InputTue() wed = InputWed() thu = InputThur() fri = InputFri() payrate = Inputrate() 'Step2. Process mon = checkmon(mon) x = payhour(mon, tue, wed, thu, fri) y = payamount(mon, tue, wed, thu, fri, x, payrate) 'Step3. Output outputreg(x, y) End Sub Function checkmon(ByVal mon As Double) 'Checks if any hours was worked on monday and if not, adds 8 hours If mon = 0 Then mon += 8 End If Return Val(mon) End Function Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BElect.Click 'Calculates pay with reference to election night 'Step0. Declarations Dim mon, tue, wed, thu, fri, x, y, payrate As Double 'Step1. Input mon = InputMon() tue = InputTue() wed = InputWed() thu = InputThur() fri = InputFri() payrate = Inputrate() 'Step2. Process tue = checktue(tue) x = payhour(mon, tue, wed, thu, fri) y = payamount(mon, tue, wed, thu, fri, x, payrate) 'Step3. Output outputreg(x, y) End Sub Function checktue(ByVal tue As Double) 'If any hours worked on tues, then adds 2 hours If tue > 0 Then tue += 2 End If Return tue End Function Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BXmas.Click 'Calculates the pay with reference to friday 'Step0. Declarations Dim mon, tue, wed, thu, fri, x, y, payrate As Double 'Step1. Input mon = InputMon() tue = InputTue() wed = InputWed() thu = InputThur() fri = InputFri() payrate = Inputrate() 'Step2. Process fri = checkfri(fri) x = payhour(mon, tue, wed, thu, fri) y = payamount(mon, tue, wed, thu, fri, x, payrate) 'Step3. Output outputreg(x, y) End Sub Function checkfri(ByVal fri As Double) 'adds 4 hours to friday work hours if hours worked >=4 If fri >= 4 Then fri += 4 End If Return fri End Function Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BReport.Click 'Outputs Actual number of hours worked this week, Average number of hours worked per day, _ 'Number of days on which this employee worked more than eight hours. Name of the day on which the employee _ 'worked the smallest number of hours, but NOT zero 'Step0. Declarations Dim mon, tue, wed, thu, fri, x, payrate, z As Double Dim y As String 'Step1. Input mon = InputMon() tue = InputTue() wed = InputWed() thu = InputThur() fri = InputFri() payrate = Inputrate() 'Step2. Process x = payhour(mon, tue, wed, thu, fri) z = calcavg(x) 'Step3. Output outputreport(x, z) moreight(mon, tue, wed, thu, fri) lowestday(mon, tue, wed, thu, fri) End Sub Function calcavg(ByVal x As Double) 'calculates the average Dim z As Double z = x / 5 Return z End Function Sub moreight(ByVal mon As Double, ByVal tue As Double, ByVal wed As Double, ByVal thu As Double, ByVal fri As Double) 'Finds out what day(s) worked over 8 hours and outputs them If mon > 8 Then outputeight("Monday") End If If tue > 8 Then outputeight("Tuesday") End If If wed > 8 Then outputeight("Wednesday") End If If thu > 8 Then outputeight("Thursday") End If If fri > 8 Then outputeight("Friday") End If End Sub Function outputeight(ByVal x As String) 'process that outputs day(s) worked over 8 hours x = Me.LOutput.Items.Add("You have worked on " & x & " more then 8 hours") Return x End Function Sub outputreport(ByVal x As Double, ByVal z As Double) 'outputs number of hours worked and average amount of hours With LOutput.Items .Add("You have worked " & x & " hours") .Add("The average amount of hours you have worked is " & z) End With End Sub Private Sub BMWF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BMWF.Click 'change the label color to GREEN for Monday, Wednesday, and Friday, and change the labels to RED for Tuesday and Thursday. 'Step0. Declarations NO declarations 'Step1. Input NO Input 'Step2. Process NO Processes 'Step3. Output mwfgreen() ttred() End Sub Private Sub BTT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTT.Click 'change the label color to GREEN for Tuesday and Thursday and change the labels to RED for Monday, Wednesday, and Friday. 'Step0. Declarations NO declarations 'Step1. Input NO Input 'Step2. Process NO Processes 'Step3. Output ttgreen() mwfred() End Sub Private Sub BSame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BSame.Click 'Changes all of the lable colors to yellow 'Step0. Declarations NO declarations 'Step1. Input NO Input 'Step2. Process NO Processes 'Step3. Output labyel() End Sub Private Sub BReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BReset.Click 'Clears all of the input fields 'Step0. Declarations NO declarations 'Step1. Input NO Input 'Step2. Process NO Processes 'Step3. Output clearinput() End Sub Private Sub BClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BClear.Click 'Clears the output area (Listbox) 'Step0. Declarations NO declarations 'Step1. Input NO Input 'Step2. Process NO Processes 'Step3. Output clearoutput() End Sub Private Sub BExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BExit.Click 'Closes the Form 'Step0. Declarations NO declarations 'Step1. Input NO Input 'Step2. Process NO Processes 'Step3. Output closeform() End Sub Sub closeform() 'closes form Me.Close() End Sub Sub clearoutput() 'clears output box Me.LOutput.Items.Clear() End Sub Sub clearinput() 'clears all input fields Me.TMon.Text = ("") Me.TTues.Text = ("") Me.TWed.Text = ("") Me.TThur.Text = ("") Me.TFri.Text = ("") Me.TRate.Text = ("") End Sub Sub mwfgreen() 'turns labels mon, wed, fri to green Lmon.BackColor = Color.Green LWed.BackColor = Color.Green LFri.BackColor = Color.Green End Sub Sub mwfred() 'turns labels mon, wed, fri to red Lmon.BackColor = Color.Red LWed.BackColor = Color.Red LFri.BackColor = Color.Red End Sub Sub ttgreen() 'turns tues, thurs to green LTues.BackColor = Color.Green Lthur.BackColor = Color.Green End Sub Sub ttred() 'turns tues, thurs to red LTues.BackColor = Color.Red Lthur.BackColor = Color.Red End Sub Sub labyel() 'turns all labels to yellow Lmon.BackColor = Color.Yellow LTues.BackColor = Color.Yellow LWed.BackColor = Color.Yellow Lthur.BackColor = Color.Yellow LFri.BackColor = Color.Yellow Lpayrate.BackColor = Color.Yellow End Sub Sub lowestday(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double, ByVal e As Double) 'finds which days are the lowest and outputs it If a <= b And a <= c And a <= d And a <= e Then LOutput.Items.Add("The day with the least hours worked is Monday") End If If b <= a And b <= c And b <= d And b <= e Then LOutput.Items.Add("The day with the least hours worked is Tuesday") End If If c <= a And c <= b And c <= d And c <= e Then LOutput.Items.Add("The day with the least hours worked is Wednesday") End If If d <= a And d <= b And d <= c And d <= e Then LOutput.Items.Add("The day with the least hours worked is Thursday") End If If e <= a And e <= b And e <= c And e <= d Then LOutput.Items.Add("The day with the least hours worked is Friday") End If End Sub End Class