I\'m a beginner at computer science, I made the following wage calculator but I
ID: 3811585 • Letter: I
Question
I'm a beginner at computer science, I made the following wage calculator but I have abasolutely no idea how to add overtime into it.
The full code is below, please give me the code I need to add and where I need to add it. I would very much appreciate it...
Public Class Form1
'Project:Wage Calculator
'Programmer:Mario Garza
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
inputHrsWorked.Clear()
inputHourlyPayRate.Clear()
answer.Text = String.Empty
inputHrsWorked.Focus()
End Sub
Private Sub input1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles inputHrsWorked.KeyPress
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
e.KeyChar <> "" AndAlso
e.KeyChar <> ControlChars.Back Then
e.Handled = True
MessageBox.Show("Input Integers Only", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles inputHrsWorked.TextChanged
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
If inputHrsWorked.Text = "" Or inputHourlyPayRate.Text = "" = True Then
MsgBox("Please Enter Required * Information....", MsgBoxStyle.Critical, "Attention...")
inputHrsWorked.Focus()
Else
Dim nhw, hpr, gpe As Double
nhw = inputHrsWorked.Text
hpr = inputHourlyPayRate.Text
gpe = nhw * hpr
answer.Text = gpe.ToString("C")
End If
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
If MessageBox.Show("Do you want to exit?", "Wage Calculator", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
Me.Close()
Else
inputHrsWorked.Focus()
End If
End Sub
Private Sub inputHourlyPayRate_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles inputHourlyPayRate.KeyPress
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
e.KeyChar <> "" AndAlso
e.KeyChar <> ControlChars.Back Then
e.Handled = True
MessageBox.Show("Input Integers Only", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Private Sub inputHourlyPayRate_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles inputHourlyPayRate.TextChanged
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
MessageBox.Show("Thank you for using my program...", "Until Next Time", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ToolTip1.SetToolTip(inputHrsWorked, "Input NOH")
ToolTip1.SetToolTip(inputHourlyPayRate, "Input RPH")
ToolTip1.SetToolTip(btnCalculate, "Calculate Gross Pay")
ToolTip1.SetToolTip(btnClear, "Clear")
ToolTip1.SetToolTip(btnExit, "Go Away")
End Sub
Private Sub CalculateGrossPayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateGrossPayToolStripMenuItem.Click
btnCalculate_Click(sender, e)
End Sub
Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
btnClear_Click(sender, e)
End Sub
Private Sub GoAwayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GoAwayToolStripMenuItem.Click
btnExit_Click(sender, e)
End Sub
End Class
Explanation / Answer
This is an easy and very general wage calculator that consists of collecting general data from the employee and the data collected is passed for the further
processing and calculating of the wage or salary of the given employee.
I would refer you to write clean code like this because it becomes very hard to understand bad written code and to add overtime to your code you just have to
decide the normal working hours and the overtime hours will start after that. Than decide the rate and give it in your program as follows.
/*This is the code you have done and is similar to your code which is without the overtime feature.
Run below to see what and where you have to add the particular code. */
import java.util.Scanner;
class Employee
{
int age;
String name, address, gender;
Scanner get = new Scanner(System.in);
Employee()
{
System.out.println("Enter Name of the Employee:");
name = get.nextLine();
System.out.println("Enter Gender of the Employee:");
gender = get.nextLine();
System.out.println("Enter Address of the Employee:");
address = get.nextLine();
System.out.println("Enter Age:");
age = get.nextInt();
}
void display()
{
System.out.println("Employee Name: "+name);
System.out.println("Age: "+age);
System.out.println("Gender: "+gender);
System.out.println("Address: "+address);
}
}
class fullTimeEmployees extends Employee
{
float salary;
int des;
fullTimeEmployee()
{
System.out.println("Enter Designation:");
des = get.nextInt();
System.out.println("Enter Salary:");
salary = get.nextFloat();
}
void display()
{
System.out.println("=============================="+" "+"Full Time Employee Details"+" "+"=============================="+" ");
super.display();
System.out.println("Salary: "+salary);
System.out.println("Designation: "+des);
}
}
class partTimeEmployees extends Employee
{
int workinghrs, rate;
partTimeEmployees()
{
System.out.println("Enter Number of Working Hours:");
workinghrs = get.nextInt();
}
void calculatepay()
{
rate = 8 * workinghrs;
}
void display()
{
System.out.println("=============================="+" "+"Part Time Employee Details"+" "+"=============================="+" ");
super.display();
System.out.println("Number of Working Hours: "+workinghrs);
System.out.println("Salary for "+workinghrs+" working hours is: $"+rate);
}
}
class Employees
{
public static void main(String args[])
{
System.out.println("================================"+" "+"Enter Full Time Employee Details"+" "+"================================"+" ");
fullTimeEmployees ob1 = new fullTimeEmployees();
partTimeEmployees ob = new partTimeEmployees();
System.out.println("================================"+" "+"Enter Part Time Employee Details"+" "+"================================"+" ");
ob1.display();
ob.calculatepay();
ob.display();
}
}
/* The code with the feature of overtime pay is given below. Hope you find it understandable so that you can code it with your own help */
import java.util.Scanner;
import java.text.NumberFormat;
import java.util.Locale;
public class PayrollProgram
public static void main( String args[] )
{
Scanner input;
NumberFormat currency = NumberFormat.getCurrencyInstance(Locale.US);
String employeeName; // Placeholder for employee name
float hoursWorked; // Number of hours worked in a week
float hourlyRate; // Employee's hourly rate
float totalPay; // total hours worked plus the hourly rate
float overtimePay; // overtime pay
System.out.println( "Employee Weekly Payroll Program ");
input = new Scanner (System.in);
System.out.println( );
System.out.print( "Enter your name: " );
employeeName = input.nextLine();
do
{
// Prompt for Employee's Hourly Rate
System.out.print( "Enter hourly rate: " );
hourlyRate = input.nextFloat();
if (hourlyRate < 0)
{
System.out.println( "ERROR: The hourly rate must be a positive number." );
}
} while ( hourlyRate < 0 );
do
{
System.out.print( "Enter total hours worked this week: " );
hoursWorked = input.nextFloat();
if (hoursWorked < 0)
{
System.out.println( "ERROR: The number of hours worked must be a positive number." );
}
} while ( hoursWorked < 0 );
// Calculate Employee's Pay
totalPay = hourlyRate * hoursWorked; /*This is the code you have to add
overtimePay = totalPay + overtimePay; into the above written code*/
// Calculate OVERTIME HOURS
if (hoursWorked > 40)
{
overtimePay = (hoursWorked - 40) * (hourlyRate * 1.5); /*This is the code you have to add
overtimePay = totalPay + overtimePay; into the above written code*/
}
else
{ totalPay = hoursWorked * hourlyRate;
overtimePay = 0;
}
System.out.println( " WEEKLY PAYROLL RESULTS");
System.out.println( " Employee Name: " + employeeName);
System.out.println( "Gross Pay: " + currency.format(totalPay) );
System.out.println( "Overtime Hours: " + overtimePay);
System.out.println( );
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.