Question

In: Computer Science

CODE: C# using System; public static class Lab6 { public static void Main() { // declare...

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
  }
}
  1. 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?

  2. Run the program using input Smith, -8,40, 12.5, 0.2.

    What is the output?

  3. Run the program using input Smith, 40,-3, 12.5, 0.2.

    What is the output?

  4. Run the program using input Smith, 40,12.5, 9, 0.2.

    What is the output?

  5. Run the program using input Smith, 44,12.5, 0.2.

    What is the output?

  6. 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.

  7. 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.)

  8. What is the output?

    How does the result differ from Part (f)?

  9. 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?

Solutions

Expert Solution

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 :


Related Solutions

public class sales_receipt { public static void main(String[] args) { //declare varables final double tax_rate =...
public class sales_receipt { public static void main(String[] args) { //declare varables final double tax_rate = 0.05; //tax rate String cashier_name = "xxx"; //sales person String article1, article2; //item name for each purchased int quantity1, quantity2; //number of quantities for each item double unit_cost1, unit_cost2; //unit price for each item double price1, price2; //calculates amounts of money for each item. double sub_total; //total price of two items without tax double tax; //amount of sales tax double total; //total price of...
Create a new Java file, containing this code public class DataStatsUser { public static void main...
Create a new Java file, containing this code public class DataStatsUser { public static void main (String[] args) { DataStats d = new DataStats(6); d.append(1.1); d.append(2.1); d.append(3.1); System.out.println("final so far is: " + d.mean()); d.append(4.1); d.append(5.1); d.append(6.1); System.out.println("final mean is: " + d.mean()); } } This code depends on a class called DataStats, with the following API: public class DataStats { public DataStats(int N) { } // set up an array (to accept up to N doubles) and other member...
public class Main { public static void main(String [] args) { int [] array1 = {5,...
public class Main { public static void main(String [] args) { int [] array1 = {5, 8, 34, 7, 2, 46, 53, 12, 24, 65}; int numElements = 10; System.out.println("Part 1"); // Part 1 // Enter the statement to print the numbers in index 5 and index 8 // put a space in between the two numbers and a new line at the end // Enter the statement to print the numbers 8 and 53 from the array above //...
---------------------------------------------------------------------------- public class Main { public static void main(String[] args) { int[] A = {11, 12,...
---------------------------------------------------------------------------- public class Main { public static void main(String[] args) { int[] A = {11, 12, -10, 13, 9, 12, 14, 15, -20, 0}; System.out.println("The maximum is "+Max(A)); System.out.println("The summation is "+Sum(A)); } static int Max(int[] A) { int max = A[0]; for (int i = 1; i < A.length; i++) { if (A[i] > max) { max = A[i]; } } return max; } static int Sum(int[] B){ int sum = 0; for(int i = 0; i --------------------------------------------------------------------------------------------------------------------------- Convert...
Task 2/2: Java program Based upon the following code: public class Main {   public static void...
Task 2/2: Java program Based upon the following code: public class Main {   public static void main( String[] args ) {     String alphabet = "ABCDEFGHIJKLMNMLKJIHGFEDCBA";     for( <TODO> ; <TODO> ; <TODO> ) {       <TODO>;     } // Closing for loop   } // Closing main() } // Closing class main() Write an appropriate loop definition and in-loop behavior to determine if the alphabet string is a palindrome or not. A palindrome is defined as a string (or more generally, a token) which...
class Main { public static void main(String[] args) {        int[] array = {1,2,3,4,5};   ...
class Main { public static void main(String[] args) {        int[] array = {1,2,3,4,5};        //Complexity Analysis //Instructions: Print the time complexity of method Q1_3 with respect to n=Size of input array. For example, if the complexity of the //algorithm is Big O nlogn, add the following code where specified: System.out.println("O(nlogn)"); //TODO }    public static void Q1_3(int[] array){ int count = 0; for(int i = 0; i < array.length; i++){ for(int j = i; j < array.length;...
public class OOPExercises {     public static void main(String[] args) {         A objA = new...
public class OOPExercises {     public static void main(String[] args) {         A objA = new A();         B objB = new B();         System.out.println("in main(): ");         System.out.println("objA.a = "+objA.getA());         System.out.println("objB.b = "+objB.getB());         objA.setA (222);         objB.setB (333.33);       System.out.println("objA.a = "+objA.getA());         System.out.println("objB.b = "+objB.getB());     } } Output: public class A {     int a = 100;     public A() {         System.out.println("in the constructor of class A: ");         System.out.println("a = "+a);         a =...
public class GreeterTest {    public static void main(String[] args)    { // create an object...
public class GreeterTest {    public static void main(String[] args)    { // create an object for Greeter class Greeter greeter = new Greeter("Jack"); // create two variables Greeter var1 = greeter; Greeter var2 = greeter; // call the sayHello method on the first Greeter variable String res1 = var1.sayHello(); System.out.println("The first reference " + res1); // Call the setName method on the secod Grreter variable var2.setName("Mike"); String res2 = var2.sayHello(); System.out.println("The second reference " + res2);    } }...
public class ArraySkills { public static void main(String[] args) { // *********************** // For each item...
public class ArraySkills { public static void main(String[] args) { // *********************** // For each item below you must code the solution. You may not use any of the // methods found in the Arrays class or the Collections classes // You must use Java's built-in Arrays. You are welcome to use the Math and/or Random class if necessary. // You MUST put your code directly beneath the comment for each item indicated. String[] myData; // 1. Instantiate the given...
------------------------------------------------------------------------------------ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input =...
------------------------------------------------------------------------------------ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int result = 0; System.out.print("Enter the first number: "); int x = input.nextInt(); System.out.print("Enter the second number: "); int y = input.nextInt(); System.out.println("operation type for + = 0"); System.out.println("operation type for - = 1"); System.out.println("operation type for * = 2"); System.out.print("Enter the operation type: "); int z = input.nextInt(); if(z==0){ result = x + y; System.out.println("The result is " + result); }else...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT