ASDV-C-Sharp/Lab4/Lab4_2_CalebFontenot/Form1.cs
2022-09-13 12:36:37 -05:00

77 lines
2.4 KiB
C#
Executable File

namespace Lab4_2_CalebFontenot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void calculateButton_Click(object sender, EventArgs e)
{
try
{
// Create variables
decimal hoursWorked,
hourlyPayRate,
basePay,
overtimeHours,
overtimePay,
grossPay;
// Define constants
const decimal BASE_HOURS = 40m,
OT_MULTIPLIER = 1.5m;
// Get data
hoursWorked = decimal.Parse(hoursWorkedTextBox.Text);
hourlyPayRate = decimal.Parse(hourlyPayRateTextBox.Text);
// Determine gross pay
if (hoursWorked > BASE_HOURS)
{
// Calculate the base pay (without overtime).
basePay = hourlyPayRate * BASE_HOURS;
// Calculate the number of overtime hours.
overtimeHours = hoursWorked - BASE_HOURS;
// Calculate the overtime pay.
overtimePay = overtimeHours * hourlyPayRate * OT_MULTIPLIER;
// Calculate the gross pay.
grossPay = basePay + overtimePay;
}
else
{
// Calculate the gross pay.
grossPay = hoursWorked * hourlyPayRate;
}
// Display the gross pay.
grossPayLabel.Text = grossPay.ToString("c");
}
catch (Exception ex)
{
// Display an error message.
MessageBox.Show(ex.Message);
}
}
private void clearButton_Click(object sender, EventArgs e)
{
// Clear all the labels!
hoursWorkedTextBox.Text = "";
hourlyPayRateTextBox.Text = "";
grossPayLabel.Text = "";
// Focus the hoursWorkedTextBox
hoursWorkedTextBox.Focus();
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}