In: Computer Science
CODE: C# using System; public static class Lab6 { public static void Main() { // declare variables int hrsWrked; double ratePay, taxRate, grossPay, netPay=0; string lastName; // enter the employee's last name Console.Write("Enter the last name of the employee => "); lastName = Console.ReadLine(); // enter (and validate) the number of hours worked (positive number) do { Console.Write("Enter the number of hours worked (> 0) => "); hrsWrked = Convert.ToInt32(Console.ReadLine()); } while (hrsWrked < 0); // enter (and validate) the hourly rate of pay (positive number) // *** Insert the code to enter and validate the ratePay // enter (and validate) the percentage of tax (between 0 and 1) // *** Insert the code to enter and validate taxRate // Call a method to calculate the gross pay (call by value) grossPay = CalculateGross(hrsWrked, ratePay); // Invoke a method to calculate the net pay (call by reference) CalculateNet(grossPay, taxRate , ref netPay); // print out the results Console.WriteLine("{0} worked {1} hours at {2:C} per hour", lastName, hrsWrked, ratePay); // *** Insert the code to print out the Gross Pay and Net Pay Console.ReadLine(); } // Method: CalculateGross // Parameters // hours: integer storing the number of hours of work // rate: double storing the hourly rate // Returns: double storing the computed gross pay public static double CalculateGross(int hours, double rate) { // *** Insert the contents of the CalculateGross Method } // Method: CalculateNet // Parameters // grossP: double storing the grossPay // tax: double storing tax percentage to be removed from gross pay // netP: call by reference double storing the computed net pay // Returns: void public static void CalculateNet(double grossP, double tax, ref double netP) { // *** Insert the details of the CalculateNet Method } }
Build the solution. Resolve any syntax mistakes (if you make any) until the program compiles. Run the program using the input data: Smith, 40, 12.5, 0.2. You should find that the gross pay is $500.00 and net pay is $400.00
What is the output?
Run the program using input Smith, -8,40, 12.5, 0.2.
What is the output?
Run the program using input Smith, 40,-3, 12.5, 0.2.
What is the output?
Run the program using input Smith, 40,12.5, 9, 0.2.
What is the output?
Run the program using input Smith, 44,12.5, 0.2.
What is the output?
Now let’s add another user-defined method to our program ... this method will compute any overtime pay.
Assume the employees receive time and a half (1.5) for any hours worked over 40).
Your method should be invoked after you compute gross pay with CalculateGross but before you compute net pay with CalculateNet (i.e., between Lines 36 and 39).
The new method is to be called CalculateOT, and it is to have to following method header:
public static double CalculateOT(int hours, double rate)In this method, both formal parameters are call by value with hours representing the number of hours work and rate representing the hourly wage.
CalculateOT is to return only the amount of overtime pay (in excess of regular pay) which is computed from the number of hours greater than 40 multiplied by the hourly wage and then multiplied by 0.5. (CalculateOT is only returning the overtime amount which must be added to the gross pay variable in Main() before netPay is calculated ) Run the program using the input data: Smith, 40, 12.5, 0.2.
Run the program using input Smith, 44,12.5, 0.2. (The grossPay for this data should be $575 and the netPay should be $460. If you get a different answer, you've made a mistake and should revisit your code.)
What is the output?
How does the result differ from Part (f)?
Run the program using input Smith, 20,12.5, 0.2.
The grossPay for this data should be $250 and the netPay should be $200. If you get a different answer, you've made a mistake and should revisit your code.
What is the output?
HI
NOTE:
1.)THIS PROGRAM HAS TWO PHASE :
A.) FIRST PHASE IS OUTPUT PRINTED BEFORE WRITING CalculateOT METHOD(OVERTIME WAGES WAS NOT CONSIDERED).
B.) SECOND PHASE IS OUTPUT PRINTED AFTER WRITING CalculateOT METHOD(OVERTIME WAGES IS CONSIDERED).
2.) TO FIND OUTPUT WITHOUT CONSIDERING OVERTIME REMOVE THE CalculateOT METHOD FROM PROGRAM.
3.) EVERY OUTPUT IS GENERATED AS EXPECTED.
4.) IF YOU GOT ANY PROBLEM/DOUBT THEN COMMENT, I WILL DO MY BEST TO HELP.
CODE:
using System;
public static class Lab6
{
public static void Main()
{
int hrsWrked;
double ratePay, taxRate, grossPay, netPay=0;
string lastName;
Console.Write("Enter the last name of the employee =>
");
lastName = Console.ReadLine();
do
{
Console.Write("Enter the number of hours worked (> 0) =>
");
hrsWrked = Convert.ToInt32(Console.ReadLine());
} while (hrsWrked < 0);
do
{
Console.Write("Enter the hourly rate of pay (> 0) =>
");
ratePay = Convert.ToDouble(Console.ReadLine());
} while (ratePay < 0);
do
{
Console.Write("Enter the percentage of tax (> 0 and < 1)
=> ");
taxRate = Convert.ToDouble(Console.ReadLine());
} while (taxRate < 0 | taxRate >= 1);
grossPay = CalculateGross(hrsWrked, ratePay);
int extraHours=hrsWrked-40; // HERE IS THE STARTING POINT
OF OVERTIME PART
if(extraHours>0)
{
double extraEarned=CalculateOT(extraHours,ratePay);
grossPay = grossPay + extraEarned;
} // ENDING POINT OF OVERTIME PART
CalculateNet(grossPay, taxRate , ref netPay);
Console.WriteLine("{0} worked {1} hours at {2:C} per hour",
lastName,
hrsWrked, ratePay);
Console.WriteLine("{0} grossPay is $ {1} and netPay is $ {2}",
lastName,
grossPay, netPay);
}
public static double CalculateGross(int hours, double rate)
{
// *** Insert the contents of the CalculateGross Method
double gPay = hours * rate;
return gPay;
}
public static void CalculateNet(double grossP, double tax, ref
double netP)
{
// *** Insert the details of the CalculateNet Method
netP=grossP-tax*grossP;
}
public static double CalculateOT(int hours, double rate)
{
double earnedExtra= hours*rate*0.5;
return earnedExtra;
}
}
OUTPUTS BEFORE OVERTIME WAS CONSIDERED:
OUTPUTS WHEN OVERTIME IS CONSIDERED :