Develop a C# app that will determine the gross pay for each of three employees
Object:
Develop a C# app that will determine the gross pay for each of three employees. The company pays straight time for the first 20 hours worked by each employee and time-and-a-half for all hours worked in excess of 20 hours. You’re given a list of the three employees of the company, the number of hours each employee worked last week, and the hourly rate of each employee. Your app should input this information for each employee, then should determine and display the employee’s gross pay. Use the Console class’s ReadLine method to input the data.C# Projects with Source Code.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace oop1b
{
class emp
{
private string emp_name;
private double emp_sal;
private double emp_hour;
public emp()
{
name = emp_name;
sal = emp_sal;
hr = emp_hour;
}
public string name
{
get { return emp_name; }
set { emp_name = value; }
}
public double sal
{
get { return emp_sal; }
set { emp_sal = value; }
}
public double hr
{
get { return emp_hour; }
set { emp_hour = value; }
}
public double calemp()
{
if (hr <= 40)
return hr * sal;
else
return (40* sal)+((hr – 40 )*(sal * 1.5));
}
public void display()
{
Console.WriteLine(“Employee Name : ” + name);
Console.WriteLine(“Employee Salary : ” + sal);
Console.WriteLine(“Employee Hours Worked: ” + hr);
Console.WriteLine(“Employee Total Pay : ” + calemp());
}
}
class Program
{
static void Main(string[] args)
{
emp [ ] e = new emp[3];
emp k = new emp();
for (int i = 1; i <= 3; i++)
{
Console.WriteLine(“Enter Employee Name : “);
k.name = Console.ReadLine();
Console.WriteLine(“Enter Employee Salary : “);
k.sal = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(“Enter Employee Hours : “);
k.hr = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(“————————————\n”);
Console.WriteLine(“Employee : ” + i,”\n”);
k.display();
Console.WriteLine(“\n————————————\n”);
}
Console.ReadKey();
}
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace oop1b { class emp { private string emp_name; private double emp_sal; private double emp_hour; public emp() { name = emp_name; sal = emp_sal; hr = emp_hour; } public string name { get { return emp_name; } set { emp_name = value; } } public double sal { get { return emp_sal; } set { emp_sal = value; } } public double hr { get { return emp_hour; } set { emp_hour = value; } } public double calemp() { if (hr <= 40) return hr * sal; else return (40 * sal) + ((hr - 40) * (sal * 1.5)); } public void display() { Console.WriteLine("Employee Name : " + name); Console.WriteLine("Employee Salary : " + sal); Console.WriteLine("Employee Hours Worked: " + hr); Console.WriteLine("Employee Total Pay : " + calemp()); } } class Program { static void Main(string[] args) { emp[] e = new emp[3]; emp k = new emp(); for (int i = 1; i <= 3; i++) { Console.WriteLine("Enter Employee Name : "); k.name = Console.ReadLine(); Console.WriteLine("Enter Employee Salary : "); k.sal = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Enter Employee Hours : "); k.hr = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("------------------------------------\n"); Console.WriteLine("Employee : " + i, "\n"); k.display(); Console.WriteLine("\n------------------------------------\n"); } Console.ReadKey(); } } }
Output:
Another C# Program: C# Program Calculating the Area of a Rectangle
Another C# Program: C# Program that Subtracts two user-defined numbers
Another C# Program: C# program to count vowels in a string
Another Program: Write a C# program that reads two arrays and checks whether they are equal.
Pingback: Write a C# program to demonstrate the multiple inheritances
Pingback: Implement bubble sort in C# the value of array given by the users
Pingback: C# how to handle exceptions to illustrate try-catch action with Exceptions