Answer to Question #253589 in C# for Waseem Saleem

Question #253589

1) Create a class Worker with attributes name, age and salary. This class contain default constructor, GetData and Display.

 

a) A function SalariedEmployeeComission calculates the commission of the worker and display total salary constantly.

 

b) A function HourlyEmployeeComission calculates the commission of the worker with of 5% and display total salary constantly

 

Note: Declare variables as per need, Commission of an employee of Salaried class is 10% and for class Hourly employee is 5%


1
Expert's answer
2021-10-19T15:19:36-0400
using System;
using System.Collections.Generic;


namespace App
{


    class Worker { 
        
        private string name;
        private int age;
        private double salary;


        public Worker() { }


        public void GetData() {
            Console.Write("Enter name: ");
            name = Console.ReadLine();
            Console.Write("Enter age: ");
            age = int.Parse(Console.ReadLine());
            Console.Write("Enter salary: ");
            salary = double.Parse(Console.ReadLine());
        }
        public void Display() {
            Console.WriteLine("\nName: {0}", name);
            Console.WriteLine("Age: {0}", age);
        }
        /// <summary>
        /// A function SalariedEmployeeComission calculates the commission of the worker and display total salary constantly.
        /// </summary>
        public void SalariedEmployeeComission()
        {
            double comPerc = 10;
            double commission = salary * comPerc / 100.0;
            double totalSalary = commission + salary;
            Console.WriteLine("Salaried Employee Commission {0}%: {1}", comPerc, commission);
            Console.WriteLine("Salaried Employee Total salary: {0}", totalSalary);
        }
        /// <summary>
        /// A function HourlyEmployeeCommission calculates the commission of Worker with of 5% and display total salary constantly
        /// </summary>
        public void HourlyEmployeeCommission()
        {
            double comPerc = 5;
            double commission = salary * comPerc / 100.0;
            double totalSalary = commission + salary;
            Console.WriteLine("Hourly Employee Commission {0}%: {1}", comPerc, commission);
            Console.WriteLine("Hourly Employee Total salary: {0}", totalSalary);
        }
    }
   


    class Program
    {
        static void Main(string[] args)
        {
            Worker w = new Worker();
            w.GetData();
            w.Display();


            w.SalariedEmployeeComission();
            Console.WriteLine();
            w.HourlyEmployeeCommission();


            Console.ReadLine();


        }


    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS