***THIS IS FOR C# PROGRAMMING*** Write an application that asks the user if he/s
ID: 3755671 • Letter: #
Question
***THIS IS FOR C# PROGRAMMING***
Write an application that asks the user if he/she is a Salary employee or an Hourly employee.
If Salary, then ask the user for their yearly wage. Divide the yearly wage by 52 and display the result as their weekly wage.
If Hourly, then ask the user for their hourly wage and the hours worked that week.
Calculate their wage based on the following rules:
Up to and including 40 hours of the hours worked are paid to the employee at their hourly wage. This is considered regular pay.
Any hours over 40 are paid at "time and a half" meaning (hourly wage * 1.5). This is considered overtime pay.
The total weekly wage for hourly workers is calculated as regular pay + overtime pay.
You should create at least 2 methods as part of this project. These methods are
CalculateWeeklyWageForSalary
CalculateWeeklyWageForHourly
Display the resulting weekly wage for the employee in currency format.
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester
{
public class Program
{
public static double CalculateWeeklyWageForSalary(double wage)
{
return wage / 52.0;
}
public static double CalculateWeeklyWageForHourly(double wage , int hours)
{
double salary;
// if no of hours worked is less than equal to 40 hours
if( hours <= 40 )
salary = (double)hours * wage;
// if no of hours worked is more 40 hours
else
salary = 40.0 * wage + ( (double)hours - 40.0 ) * 1.5 * wage;
return salary;
}
public static void Main(string[] args)
{
//Your code goes here
Console.WriteLine("Select the type of employee ...");
Console.WriteLine("1. Salary Employee");
Console.WriteLine("2. Hourly EMployee");
// read complete line and convert into int
int n = Convert.ToInt32(Console.ReadLine());
double salary = 0.0;
// if Salary Employee
if( n == 1 )
{
Console.Write(" Enter yearly wage : ");
// read complete line and convert into double
double wage = Convert.ToDouble(Console.ReadLine());
salary = CalculateWeeklyWageForSalary(wage);
}
else
{
Console.Write(" Enter hourly wage : ");
// read complete line and convert into double
double wage = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter no of hours worked : ");
// read complete line and convert into int
int hours = Convert.ToInt32(Console.ReadLine());
salary = CalculateWeeklyWageForHourly(wage , hours);
}
Console.WriteLine(" Salary : $" + salary);
}
}
}
Sample Output
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.