Implement in C sharp, create a derived class Salesman that will implement the me
ID: 3590151 • Letter: I
Question
Implement in C sharp, create a derived class Salesman that will implement the method PaySalary. The salary paid to each salesman has two parts: base salary and bonus. The base salary of each salesman is $30,000. A salesman with sale over $40,000 get a higher bonus (bonus=sale*20%). Otherwise, the bonus will be bonus*10%. In addition, the class Salesman has a field Sale used to calculate the bonus of each employee. It has a constructor having one parameter. When it is called, the field Sale is initialized via this parameter.
Explanation / Answer
using System;
class Salesman
{
private double sale;
public Salesman(double sale) //argument constructor
{
this.sale = sale;
}
public double paySalary(double sale) //method to calculate salary
{
if(sale > 40000)
return (30000+ sale*0.2);
else
return (30000 +sale*0.1);
}
}
public class Test
{
public static void Main()
{
Console.WriteLine("Enter the sale of salesman : ");
double sale = Convert.ToDouble(Console.ReadLine());
Salesman s1 = new Salesman(sale);
Console.WriteLine(" The salary of the salesman : $"+ s1.paySalary(sale));
}
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.