Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I was asked to design a payroll application but the code is not coming out corre

ID: 3626976 • Letter: I

Question


I was asked to design a payroll application but the code is not coming out correct!! Please help

This is my code:


Public Class Form1
Inherits System.Windows.Forms.Form
Const decReMeals As Decimal = CDec(37.0)
Const decReParkingFees As Decimal = CDec(10.0)
Const decReTaxi As Decimal = CDec(20.0)
Const decReLodge As Decimal = CDec(95.0)
Const decReMiles As Decimal = CDec(0.27)
Const decReTotal As Decimal = decReMeals + decReParkingFees + decReTaxi + decReLodge + decReMiles


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click

Dim intNumberOfDays As Integer
Dim decAirFare As Decimal
Dim decCarRent As Decimal
Dim decMiles As Decimal
Dim decParkingFees As Decimal
Dim decTaxi As Decimal
Dim decSemReg As Decimal
Dim decLodge As Decimal
Dim decTotalInc As Decimal
Try
intNumberOfDays = CInt(CInt(txtDays.Text) >= 1)
Catch ex As Exception
MessageBox.Show("Number of days cannot be less than 1.")
Return
End Try
Try
decAirFare = CDec(CDec(txtAirfare.Text) >= 0)
decCarRent = CDec(CDec(txtCar.Text) >= 0)
decMiles = CDec(CDec(txtMiles.Text) >= 0)
decParkingFees = CDec(CDec(txtParking.Text) >= 0)
decTaxi = CDec(CDec(txtTaxi.Text) >= 0)
decSemReg = CDec(CDec(txtConference.Text) >= 0)
decLodge = CDec(CDec(txtLodging.Text) >= 0)
Catch ex As Exception
MessageBox.Show("Input amounts cannot be less than zero please enter a zero for any empty fields. Input Error")
Return

End Try
decTotalInc = CDec(CDec(txtAirfare.Text) + CDec(txtCar.Text) + CDec(txtMiles.Text) + CDec(txtParking.Text) + CDec(txtTaxi.Text) + CDec(txtConference.Text) + CDec(txtLodging.Text))
lblTotalInc.Text = FormatCurrency(decTotalInc.ToString)

CalcMeals()
CalcMileage()
CalcParkingFees()
CalcTaxiFees()
CalcLodging()
CalcTotalReimbursement()
CalcUnallowed()
CalcSaved()


End Sub
Sub CalcMeals()
Dim decMealsRe As Decimal
decMealsRe = CDec(txtDays.Text) * decReMeals
End Sub
Sub CalcMileage()
Dim decMilesRe As Decimal
decMilesRe = CDec(txtMiles.Text) * decReMiles
End Sub
Sub CalcParkingFees()
Dim decParkingFeesRe As Decimal
decParkingFeesRe = CDec(txtParking.Text) - CDec(CDec(txtDays.Text) * decReParkingFees)


End Sub
Sub CalcTaxiFees()
Dim decTaxiFeesRe As Decimal
decTaxiFeesRe = CDec(txtTaxi.Text) - CDec(CDec(txtDays.Text) * decReTaxi)

End Sub
Sub CalcLodging()
Dim decLodgingRe As Decimal
decLodgingRe = CDec(txtLodging.Text) - CDec(CDec(txtDays.Text) * decReLodge)

End Sub
Sub CalcTotalReimbursement()
Dim decTotalRe As Decimal
Dim decMealsRe As Decimal
Dim decMilesRe As Decimal
Dim decParkingFeesRe As Decimal
Dim decTaxiFeesRe As Decimal
Dim decLodgingRe As Decimal

CalcMeals()
CalcMileage()
CalcParkingFees()
CalcTaxiFees()
CalcLodging()
decTotalRe = decMealsRe + decMilesRe + decParkingFeesRe + decTaxiFeesRe + decLodgingRe
lblTotalInc.Text = FormatCurrency(decTotalRe.ToString)

End Sub
Sub CalcUnallowed()
Dim decTotalExc As Decimal
Dim decTotalInc As Decimal
Dim decTotalRe As Decimal
decTotalExc = decTotalInc - decTotalRe
lblTotalExc.Text = FormatCurrency(decTotalExc.ToString)

End Sub
Sub CalcSaved()
Dim decSaved As Decimal
Dim decTotalAll As Decimal
decSaved = decReTotal - decTotalAll

lblSav.Text = FormatCurrency(decSaved.ToString)

End Sub


Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'Clears all the labels and textboxes
txtDays.Clear()
txtAirfare.Clear()
txtCar.Clear()
txtLodging.Clear()
txtMiles.Clear()
txtParking.Clear()
txtTaxi.Clear()
txtConference.Clear()
lblAll.Text = String.Empty
lblSav.Text = String.Empty
lblExc.Text = String.Empty
lblTotalInc.Text = String.Empty

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Closes the application
Me.Close()
End Sub
End Class

Explanation / Answer

Dear,

Your modified code is:

Public Class Form1

    Inherits System.Windows.Forms.Form

    Const decReMeals As Decimal = CDec(37.0)

    Const decReParkingFees As Decimal = CDec(10.0)

    Const decReTaxi As Decimal = CDec(20.0)

    Const decReLodge As Decimal = CDec(95.0)

    Const decReMiles As Decimal = CDec(0.27)

    Const decReTotal As Decimal = decReMeals + decReParkingFees + decReTaxi + decReLodge + decReMiles

    Dim decTotalInc As Decimal

 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

 

    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click

        Dim intNumberOfDays As Integer

        Dim decAirFare As Decimal

        Dim decCarRent As Decimal

        Dim decMiles As Decimal

        Dim decParkingFees As Decimal

        Dim decTaxi As Decimal

        Dim decSemReg As Decimal

        Dim decLodge As Decimal

 

        Try

            intNumberOfDays = CInt(CInt(txtDays.Text) >= 1)

        Catch ex As Exception

            MessageBox.Show("Number of days cannot be less than 1.")

            Return

        End Try

        Try

            decAirFare = CDec(CDec(txtAirfare.Text) >= 0)

            decCarRent = CDec(CDec(txtCar.Text) >= 0)

            decMiles = CDec(CDec(txtMiles.Text) >= 0)

            decParkingFees = CDec(CDec(txtParking.Text) >= 0)

            decTaxi = CDec(CDec(txtTaxi.Text) >= 0)

            decSemReg = CDec(CDec(txtConference.Text) >= 0)

            decLodge = CDec(CDec(txtLodging.Text) >= 0)

        Catch ex As Exception

            MessageBox.Show("Input amounts cannot be less than zero please enter a zero for any empty fields. Input Error")

            Return

 

        End Try

        decTotalInc = CDec(CDec(txtAirfare.Text) + CDec(txtCar.Text) + CDec(txtMiles.Text) + CDec(txtParking.Text) + CDec(txtTaxi.Text) + CDec(txtConference.Text) + CDec(txtLodging.Text))

        lblAll.Text = FormatCurrency(decTotalInc.ToString)

 

        'CalcMeals()

        'CalcMileage()

        'CalcParkingFees()

        'CalcTaxiFees()

        'CalcLodging()

        'CalcTotalReimbursement()

        CalcUnallowed()

        'CalcSaved()

    End Sub

 

    Function CalcMeals() As Decimal

        Dim decMealsRe As Decimal

        decMealsRe = CDec(txtDays.Text) * decReMeals

        Return decMealsRe

    End Function

 

    Function CalcMileage() As Decimal

        Dim decMilesRe As Decimal

        decMilesRe = CDec(txtMiles.Text) * decReMiles

        Return decMilesRe

    End Function

 

    Function CalcParkingFees() As Decimal

        Dim decParkingFeesRe As Decimal

        decParkingFeesRe = CDec(txtParking.Text) - CDec(CDec(txtDays.Text) * decReParkingFees)

        Return decParkingFeesRe

    End Function

 

    Function CalcTaxiFees() As Decimal

        Dim decTaxiFeesRe As Decimal

        decTaxiFeesRe = CDec(txtTaxi.Text) - CDec(CDec(txtDays.Text) * decReTaxi)

        Return decTaxiFeesRe

    End Function

 

    Function CalcLodging() As Decimal

        Dim decLodgingRe As Decimal

        decLodgingRe = CDec(txtLodging.Text) - CDec(CDec(txtDays.Text) * decReLodge)

        Return decLodgingRe

    End Function

 

    Function CalcTotalReimbursement() As Decimal

        Dim decTotalRe As Decimal

        Dim decMealsRe As Decimal

        Dim decMilesRe As Decimal

        Dim decParkingFeesRe As Decimal

        Dim decTaxiFeesRe As Decimal

        Dim decLodgingRe As Decimal

 

        decMealsRe = CalcMeals()

        decMilesRe = CalcMileage()

        decParkingFeesRe = CalcParkingFees()

        decTaxiFeesRe = CalcTaxiFees()

        decLodgingRe = CalcLodging()

        decTotalRe = decMealsRe + decMilesRe + decParkingFeesRe + decTaxiFeesRe + decLodgingRe

        lblTotalInc.Text = FormatCurrency(decTotalRe.ToString)

        Return decTotalRe

    End Function

 

    Sub CalcUnallowed()

        Dim decTotalExc As Decimal

        Dim decTotalRe As Decimal

        decTotalRe = CalcTotalReimbursement()

        decTotalExc = decTotalInc - decTotalRe

        lblTotalExc.Text = FormatCurrency(decTotalExc.ToString)

    End Sub

 

    Sub CalcSaved()

        Dim decSaved As Decimal

        Dim decTotalAll As Decimal

        decSaved = decReTotal - decTotalAll

        lblSav.Text = FormatCurrency(decSaved.ToString)

    End Sub

 

 

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

        'Clears all the labels and textboxes

        txtDays.Clear()

        txtAirfare.Clear()

        txtCar.Clear()

        txtLodging.Clear()

        txtMiles.Clear()

        txtParking.Clear()

        txtTaxi.Clear()

        txtConference.Clear()

        lblAll.Text = String.Empty

        lblSav.Text = String.Empty

        lblExc.Text = String.Empty

        lblTotalInc.Text = String.Empty

        lblTotalExc.Text = String.Empty

    End Sub

 

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

        'Closes the application

        Me.Close()

    End Sub

End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote