Answer to Question #253249 in C# for Dani

Question #253249
: 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 HourlyEmployeeCommission calculates the commission of Worker with of
5% and display total salary constantly
1
Expert's answer
2021-10-19T02:05:46-0400
using System;
using System.Collections.Generic;


namespace App
{


    class Worker { 
        //with attributes name, age and salary. 
        private string name;
        private int age;
        private double salary;
        private double commissionPerc;


        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());
            Console.Write("Enter commission for salaried employee: ");
            commissionPerc = double.Parse(Console.ReadLine());
        }
        public void Display() {
            Console.WriteLine("Name: {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 commission = salary * commissionPerc / 100.0;
            double totalSalary = commission + salary;
            Console.WriteLine("Salaried Employee Commission {0}%: {1}", commissionPerc, 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()
        {
            commissionPerc = 5;
            double commission = salary * commissionPerc / 100.0;
            double totalSalary = commission + salary;
            Console.WriteLine("Hourly Employee Commission {0}%: {1}", commissionPerc, commission);
            Console.WriteLine("Hourly Employee Total salary: {0}", totalSalary);
        }
    }
   


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


            Worker.SalariedEmployeeComission();
            Console.WriteLine();
            Worker.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