Answer to Question #266664 in C# for Israel

Question #266664

Write a program that includes an Employee class that can be used to calculate and print the take home pay for a commissioned sales employee. All Employee receives 7% of the total sales. Income tax rate is 18%. Retirement contribution is 10%. Social security tax is 6%. Write instance methods to calculate the commission, income tax and social security tax withholding amounts as well as the amount withheld for retirement. Use appropriate constants. Design an object oriented solution and write constructors. Include at least one mutator and one accessor method; provide properties for the other instance variables. Create a second class to test your design. Allow the user to enter values for the name of the employee and the sales amount for the week in the second class.

 

 


1
Expert's answer
2021-11-16T05:22:00-0500


using System;
using System.Collections.Generic;


namespace App
{
    class Employee
    {
        // All Employee receives 7% of the total sales. 
        private const double TOTAL_SALES_RATE = 0.07;
        //Income tax rate is 18%. 
        private const double INCOME_RATE = 0.18;
        //Retirement contribution is 10%. 
        private const double RETIREMENT_CONTRIBUTION = 0.1;
        //Social security tax is 6%. 
        private const double SOCIAL_SECURITY_TAX_RATE = 0.06;


        private string name;
        private double salesAmount;


        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        


        public double SalesAmount
        {
            get { return salesAmount; }
            set { salesAmount = value; }
        }


        public Employee() { }


        public Employee(string name, double salesAmount)
        {
            this.name = name;
            this.salesAmount = salesAmount;
        }




        public double calculateCommission()
        {
            return this.salesAmount * TOTAL_SALES_RATE;
        }
        public double calculateIncomeTax()
        {
            return this.salesAmount * INCOME_RATE;
        }
        public double calculateRetirementContribution()
        {
            return this.salesAmount * RETIREMENT_CONTRIBUTION;
        }
        public double calculateSocialSecurityTax()
        {
            return this.salesAmount * SOCIAL_SECURITY_TAX_RATE;
        }
        public double calculateTotalPay()
        {
            return this.salesAmount + calculateCommission() - calculateIncomeTax() - calculateRetirementContribution() - calculateSocialSecurityTax();
        }
    }




    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter the name of the employee: ");
            string name=Console.ReadLine();
            Console.Write("Enter the sales amount for the week: ");
            double salesAmount =double.Parse(Console.ReadLine());


            Employee employee = new Employee(name, salesAmount);
            
            
            Console.WriteLine("Commission (7%): {0}", employee.calculateCommission().ToString("C"));
            Console.WriteLine("Income tax rate (18%): {0}", employee.calculateIncomeTax().ToString("C"));
            Console.WriteLine("Retirement contribution (10%): {0}", employee.calculateRetirementContribution().ToString("C"));
            Console.WriteLine("Social security tax (6%): {0}", employee.calculateSocialSecurityTax().ToString("C"));
            Console.WriteLine("Total: {0}", employee.calculateTotalPay().ToString("C"));




            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