F# Example Application: Payroll Evaluation - 1 Week
F# Example Application: Payroll Evaluation - 1 Week
Introduction
In this introductory lesson on F#, we will use a conditional statement to validate a condition and perform some simple calculations.
Practical Learning: Creating the Application
printfn "Payroll Evaluation" printfn "-------------------------------------------------------" printfn "Enter the following pieces of information" printfn "-------------------------------------------------------" printfn "Employee Information" printfn "-------------------------------------------------------" printf "First Name: "; let firstName : string = stdin.ReadLine() printf "Last Name: " let lastName : string = stdin.ReadLine() printf "Hourly Salary: " let hSalary = float(stdin.ReadLine()) printfn "-------------------------------------------------------" printfn "Time worked" printfn "-------------------------------------------------------" printf "Monday: " let monday : double = float(stdin.ReadLine()) printf "Tuesday: " let tuesday : double = float(stdin.ReadLine()) printf "Wednesday: " let wednesday : double = float(stdin.ReadLine()) printf "Thursday: " let thursday : double = float(stdin.ReadLine()) printf "Friday: " let friday : double = float(stdin.ReadLine()) let timeWorked = monday + tuesday + wednesday + thursday + friday let mutable regTime = timeWorked let mutable overtime = 0.00 let mutable regPay = hSalary * timeWorked let mutable overPay = 0.00 if timeWorked > 40.00 then regTime <- 40.00 overtime <- timeWorked - 40.00 regPay <- hSalary * 40.00 overPay <- hSalary * 1.50 * overtime let netPay = regPay + overPay; printfn "=======================================================" printfn "Payroll Evaluation" printfn "=======================================================" printfn "Employee Information" printfn "-------------------------------------------------------" printfn "Full Name: %s %s" firstName lastName printfn "Hourly Salary: %0.2f" hSalary printfn "=======================================================" printfn "Time Worked Summary" printfn "--------+---------+-----------+----------+-------------" printfn " Monday | Tuesday | Wednesday | Thursday | Friday" printfn "--------+---------+-----------+----------+-------------" printfn "%6.2f | %6.2f | %7.2f | %7.2f | %6.2f" monday tuesday wednesday thursday friday printfn "========+=========+===========+==========+=============" printfn " Pay Summary" printfn "-------------------------------------------------------" printfn " Time Pay" printfn "-------------------------------------------------------" printfn " Regular:%8.2f %9.2f" regTime regPay printfn "-------------------------------------------------------" printfn " Overtime:%7.2f %9.2f" overtime overPay printfn "=======================================================" printfn " Net Pay:%18.2f" netPay printfn "======================================================="
First Name: | Michael |
Last Name: | Carlock |
Hourly Salary: | 31.67 |
Monday | 7 |
Tuesday: | 8 |
Wednesday: | 6.5 |
Thursday: | 8.5 |
Friday: | 7.5 |
Payroll Evaluation ------------------------------------------------------- Enter the following pieces of information ------------------------------------------------------- Employee Information ------------------------------------------------------- First Name: Michael Last Name: Carlock Hourly Salary: 31.67 ------------------------------------------------------- Time worked ------------------------------------------------------- Monday: 7 Tuesday: 8 Wednesday: 6.5 Thursday: 8.5 Friday: 7.5 ======================================================= Payroll Evaluation ======================================================= Employee Information ------------------------------------------------------- Full Name: Michael Carlock Hourly Salary: 31.67 ======================================================= Time Worked Summary --------+---------+-----------+----------+------------- Monday | Tuesday | Wednesday | Thursday | Friday --------+---------+-----------+----------+------------- 7.00 | 8.00 | 6.50 | 8.50 | 7.50 ========+=========+===========+==========+============= Pay Summary ------------------------------------------------------- Time Pay ------------------------------------------------------- Regular: 37.50 1187.62 ------------------------------------------------------- Overtime: 0.00 0.00 ======================================================= Net Pay: 1187.62 ======================================================= Press any key to close this window . . .
Using an Opposite Conditional Statement
In the previous section, we use a Greater Than operator to check a condition. That operator has an opposite, which is the Less Than Or Equal operator. We will uase apply as an example.
Practical Learning: Using an Opposite Conditional Statement
printfn "Payroll Evaluation" printfn "-------------------------------------------------------" printfn "Enter the following pieces of information" printfn "-------------------------------------------------------" printfn "Employee Information" printfn "-------------------------------------------------------" printf "First Name: "; let firstName : string = stdin.ReadLine() printf "Last Name: " let lastName : string = stdin.ReadLine() printf "Hourly Salary: " let hSalary = float(stdin.ReadLine()) printfn "-------------------------------------------------------" printfn "Time worked" printfn "-------------------------------------------------------" printf "Monday: " let monday : double = float(stdin.ReadLine()) printf "Tuesday: " let tuesday : double = float(stdin.ReadLine()) printf "Wednesday: " let wednesday : double = float(stdin.ReadLine()) printf "Thursday: " let thursday : double = float(stdin.ReadLine()) printf "Friday: " let friday : double = float(stdin.ReadLine()) let timeWorked = monday + tuesday + wednesday + thursday + friday let mutable regTime = 40.00 let mutable overtime = timeWorked - 40.00 let mutable regPay = hSalary * 40.00 let mutable overPay = hSalary * 1.50 * overtime if timeWorked <= 40.00 then regTime <- timeWorked overtime <- 0.00 regPay <- hSalary * timeWorked overPay <- 0.00 let netPay = regPay + overPay; printfn "=======================================================" printfn "Payroll Evaluation" printfn "=======================================================" printfn "Employee Information" printfn "-------------------------------------------------------" printfn "Full Name: %s %s" firstName lastName printfn "Hourly Salary: %0.2f" hSalary printfn "=======================================================" printfn "Time Worked Summary" printfn "--------+---------+-----------+----------+-------------" printfn " Monday | Tuesday | Wednesday | Thursday | Friday" printfn "--------+---------+-----------+----------+-------------" printfn "%6.2f | %6.2f | %7.2f | %7.2f | %6.2f" monday tuesday wednesday thursday friday printfn "========+=========+===========+==========+=============" printfn " Pay Summary" printfn "-------------------------------------------------------" printfn " Time Pay" printfn "-------------------------------------------------------" printfn " Regular:%8.2f %9.2f" regTime regPay printfn "-------------------------------------------------------" printfn " Overtime:%7.2f %9.2f" overtime overPay printfn "=======================================================" printfn " Net Pay:%18.2f" netPay printfn "======================================================="
First Name: | Catherine |
Last Name: | Busbey |
Hourly Salary: | 24.37 |
Monday | 9.50 |
Tuesday: | 8 |
Wednesday: | 10.50 |
Thursday: | 9 |
Friday: | 10.50 |
Payroll Evaluation ------------------------------------------------------- Enter the following pieces of information ------------------------------------------------------- Employee Information ------------------------------------------------------- First Name: Catherine Last Name: Busbey Hourly Salary: 24.37 ------------------------------------------------------- Time worked ------------------------------------------------------- Monday: 9.5 Tuesday: 8 Wednesday: 10.5 Thursday: 9 Friday: 10.5 ======================================================= Payroll Evaluation ======================================================= Employee Information ------------------------------------------------------- Full Name: Catherine Busbey Hourly Salary: 24.37 ======================================================= Time Worked Summary --------+---------+-----------+----------+------------- Monday | Tuesday | Wednesday | Thursday | Friday --------+---------+-----------+----------+------------- 9.50 | 8.00 | 10.50 | 9.00 | 10.50 ========+=========+===========+==========+============= Pay Summary ------------------------------------------------------- Time Pay ------------------------------------------------------- Regular: 40.00 974.80 ------------------------------------------------------- Overtime: 7.50 274.16 ======================================================= Net Pay: 1248.96 ======================================================= Press any key to close this window . . .
|
|||
Home | Copyright © 2001-2025, FunctionX | Saturday 21 December 2024, 18:38 | Home |
|