Visual Basic Console Application: Payroll Evaluation - 1 Week
Visual Basic Console Application: Payroll Evaluation - 1 Week
Introduction
In this introductory lesson to the Visual Basic Language, we will create a small console application and perform some simple calculations.
Practical Learning: Creating the Application
Module Program Sub Main(args As String()) Console.WriteLine("Payroll Evaluation") Console.WriteLine("===================================================") Console.WriteLine("Enter the following pieces of information") Console.WriteLine("---------------------------------------------------") Console.WriteLine("Employee Information") Console.WriteLine("---------------------------------------------------") Console.Write("First Name: ") Dim FirstName = Console.ReadLine() Console.Write("Last Name: ") Dim LastName = Console.ReadLine() Console.Write("Hourly Salary: ") Dim HourlySalary = CDbl(Console.ReadLine()) Console.WriteLine("===================================================") Console.WriteLine("Time worked") Console.WriteLine("---------------------------------------------------") Console.Write("Monday: ") Dim Monday = CDbl(Console.ReadLine()) Console.Write("Tuesday: ") Dim Tuesday = CDbl(Console.ReadLine()) Console.Write("Wednesday: ") Dim Wednesday = CDbl(Console.ReadLine()) Console.Write("Thursday: ") Dim Thursday = CDbl(Console.ReadLine()) Console.Write("Friday: ") Dim Friday = CDbl(Console.ReadLine()) Dim TimeWorked = Monday + Tuesday + Wednesday + Thursday + Friday Dim RegularTime = TimeWorked Dim OverTime = 0.00 Dim OvertimePay = 0.00 Dim RegularPay = HourlySalary * TimeWorked If TimeWorked > 40.0 Then RegularTime = 40.0 RegularPay = HourlySalary * 40.0 OverTime = TimeWorked - 40.0 OvertimePay = HourlySalary * 1.5 * OverTime End If Dim NetPay = RegularPay + OvertimePay Console.WriteLine("===================================================") Console.WriteLine("Payroll Evaluation") Console.WriteLine("===================================================") Console.WriteLine("Employee Information") Console.WriteLine("---------------------------------------------------") Console.WriteLine($"Full Name: {FirstName} {LastName}") Console.WriteLine($"Hourly Salary: {HourlySalary:f}") Console.WriteLine("===================================================") Console.WriteLine("Time Worked Summary") Console.WriteLine("--------+---------+-----------+----------+---------") Console.WriteLine(" Monday | Tuesday | Wednesday | Thursday | Friday") Console.WriteLine("--------+---------+-----------+----------+---------") Console.WriteLine("{0,6:f} | {1,6:f} | {2,7:f} | {3,7:f} | {4,5:f}", Monday, Tuesday, Wednesday, Thursday, Friday) Console.WriteLine("========+=========+===========+==========+=========") Console.WriteLine(" Pay Summary") Console.WriteLine("---------------------------------------------------") Console.WriteLine(" Time Pay") Console.WriteLine("---------------------------------------------------") Console.WriteLine(" Regular:{0,9:f}{1,12:f}", RegularTime, RegularPay) Console.WriteLine("---------------------------------------------------") Console.WriteLine(" Overtime:{0,8:f}{1,12:f}", OverTime, OvertimePay) Console.WriteLine("===================================================") Console.WriteLine(" Net Pay:{0,21:f}", NetPay) Console.WriteLine("===================================================") End Sub End Module
First Name: | Michael |
Last Name: | Carlock |
Hourly Salary: | 28.25 |
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: 28.46 =================================================== 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: 28.46 =================================================== 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 1067.25 --------------------------------------------------- Overtime: 0.00 0.00 =================================================== Net Pay: 1067.25 =================================================== 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
Module Program Sub Main(args As String()) Console.WriteLine("Payroll Evaluation") Console.WriteLine("===================================================") Console.WriteLine("Enter the following pieces of information") Console.WriteLine("---------------------------------------------------") Console.WriteLine("Employee Information") Console.WriteLine("---------------------------------------------------") Console.Write("First Name: ") Dim FirstName = Console.ReadLine() Console.Write("Last Name: ") Dim LastName = Console.ReadLine() Console.Write("Hourly Salary: ") Dim HourlySalary = CDbl(Console.ReadLine()) Console.WriteLine("===================================================") Console.WriteLine("Time worked") Console.WriteLine("---------------------------------------------------") Console.Write("Monday: ") Dim Monday = CDbl(Console.ReadLine()) Console.Write("Tuesday: ") Dim Tuesday = CDbl(Console.ReadLine()) Console.Write("Wednesday: ") Dim Wednesday = CDbl(Console.ReadLine()) Console.Write("Thursday: ") Dim Thursday = CDbl(Console.ReadLine()) Console.Write("Friday: ") Dim Friday = CDbl(Console.ReadLine()) Dim TimeWorked = Monday + Tuesday + Wednesday + Thursday + Friday Dim RegularTime = 40.0 Dim OverTime = TimeWorked - 40.0 Dim RegularPay = HourlySalary * 40.0 Dim OvertimePay = HourlySalary * 1.5 * OverTime If TimeWorked <= 40.0 Then RegularTime = TimeWorked OverTime = 0.0 RegularPay = HourlySalary * TimeWorked OvertimePay = 0.00 End If Dim NetPay = RegularPay + OvertimePay Console.WriteLine("===================================================") Console.WriteLine("Payroll Evaluation") Console.WriteLine("===================================================") Console.WriteLine("Employee Information") Console.WriteLine("---------------------------------------------------") Console.WriteLine($"Full Name: {FirstName} {LastName}") Console.WriteLine($"Hourly Salary: {HourlySalary:f}") Console.WriteLine("===================================================") Console.WriteLine("Time Worked Summary") Console.WriteLine("--------+---------+-----------+----------+---------") Console.WriteLine(" Monday | Tuesday | Wednesday | Thursday | Friday") Console.WriteLine("--------+---------+-----------+----------+---------") Console.WriteLine("{0,6:f} | {1,6:f} | {2,7:f} | {3,7:f} | {4,5:f}", Monday, Tuesday, Wednesday, Thursday, Friday) Console.WriteLine("========+=========+===========+==========+=========") Console.WriteLine(" Pay Summary") Console.WriteLine("---------------------------------------------------") Console.WriteLine(" Time Pay") Console.WriteLine("---------------------------------------------------") Console.WriteLine(" Regular:{0,9:f}{1,12:f}", RegularTime, RegularPay) Console.WriteLine("---------------------------------------------------") Console.WriteLine(" Overtime:{0,8:f}{1,12:f}", OverTime, OvertimePay) Console.WriteLine("===================================================") Console.WriteLine(" Net Pay:{0,21:f}", NetPay) Console.WriteLine("===================================================") End Sub End Module
First Name: | Catherine |
Last Name: | Busbey |
Hourly Salary: | 24.37 |
Monday | 9.5 |
Tuesday: | 8 |
Wednesday: | 10.5 |
Thursday: | 9 |
Friday: | 10.5 |
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: 8.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 | 8.50 ========+=========+===========+==========+========= Pay Summary --------------------------------------------------- Time Pay --------------------------------------------------- Regular: 40.00 974.80 --------------------------------------------------- Overtime: 5.50 201.05 =================================================== Net Pay: 1175.85 =================================================== Press any key to close this window . . .
|
|||
Home | Copyright © 2001-2025, FunctionX | Sunday 14 December 2024, 15:12 | Home |
|