Please code using C Review Figure 124 below Create a class c

Please code using C# Review Figure 12.4 below Create a class called Volunteerthat inherits from the Employee class in Figure 12.4. (Note that Employee is an abstract class). .Derived classes which extend this class MUST provide the Earning () calculation in the derived class. So you must implement the Earning method in your Volunteer class. In yourVolunteerclass, Earnings() should calculate a tax-break that the volunteer earns. The tax break is calculated as $0.75 per 3 hours volunteered. · Your class should contain a constructor that inherits from the Employee class and initializes the instance variables. The Volunteer class should add an instance variable for the name of the company name where the volunteer service occurred and also a variable for hours volunteered. Create properties for them also. Create a second class that prompts the user for the information fortwo Volunteers, creates the 2 Volunteer objects, and then displays each Volunteer.

Solution

Find the answer below:

========================================================================

using System.IO;
using System;

public abstract class Employee{
    public string FirstName {get;private set;}
     public string LastName {get;private set;}
      public string SocialSecurityNumber {get;private set;}
    public Employee(string first ,string last,string ssn){
        // Console.WriteLine(\"In Employee Constructore ...\");
        FirstName = first;
        LastName = last;
        SocialSecurityNumber = ssn;
    }
    public override string ToString(){
        return string.Format(\"{0} {1} \ social security number {2}\",FirstName,LastName,SocialSecurityNumber);
    }
  
    public abstract decimal Earnings();
  
}
class Volunteer : Employee
{
    public string CompanytName {get;private set;}
    public decimal Hours {get;private set;}
    public Volunteer(string first ,string last,string ssn,string cmpn,decimal hr):base(first,last,ssn){
         //Console.WriteLine(\"In Volunteer Constructore ...\");
      
        CompanytName = cmpn;
        Hours = hr;
    }
   public override string ToString(){
        return string.Format(\"{0} {1} \ social security number : {2}\ Company Name : {3}\ Hours : {4}\",FirstName,LastName,SocialSecurityNumber,CompanytName,Hours);

    }
    public override decimal Earnings(){
        Console.WriteLine(\"In Earnings...\");
        return (((3*75*Hours)/300));
    }
}
class Test{
  
    static void Main()
    {
        string firstname,lastname,socialsecurity_num,company;
        decimal hours;
        Volunteer volunteer1 = null;
        Volunteer volunteer2 = null;
        for(int i=1;i<=2;i=i+1)
        {
        Console.WriteLine(\"Enter FirstName\");
        firstname = Console.ReadLine();
        Console.WriteLine(\"Enter LastName\");
        lastname = Console.ReadLine();
        Console.WriteLine(\"Enter socila security number\");
        socialsecurity_num = Console.ReadLine();
        Console.WriteLine(\"Enter company name\");
        company = Console.ReadLine();
        Console.WriteLine(\"Enter hours\");
        Decimal.TryParse(Console.ReadLine(), out hours);
        if(i==1) volunteer1 = new Volunteer(firstname,lastname,socialsecurity_num,company,hours);
        if(i==2) volunteer2 = new Volunteer(firstname,lastname,socialsecurity_num,company,hours);
        }
  
    Console.WriteLine(volunteer1 +\" Earnings :\"+ volunteer1. Earnings());
    Console.WriteLine(volunteer2 +\" Earnings :\"+ volunteer2. Earnings());
    }
}


=======================================================================

INPUT:

Enter FirstName                                                                                                                                                          

xyz                                                                                                                                                                      

Enter LastName                                                                                                                                                           

abc                                                                                                                                                                      

Enter socila security number                                                                                                                                             

hello                                                                                                                                                                    

Enter company name                                                                                                                                                       

defgh                                                                                                                                                                    

Enter hours                                                                                                                                                              

12                                                                                                                                                                       

Enter FirstName                                                                                                                                                          

hgi                                                                                                                                                                      

Enter LastName                                                                                                                                                           

jkl                                                                                                                                                                      

Enter socila security number                                                                                                                                             

howareyou                                                                                                                                                                

Enter company name                                                                                                                                                       

bjjs                                                                                                                                                                     

Enter hours                                                                                                                                                              

20           

=======================================================================

OUTPUT:

In Earnings...                                                                                                                                                           

xyz abc                                                                                                                                                                  

social security number : hello                                                                                                                                           

Company Name : defgh                                                                                                                                                     

Hours : 12 Earnings :9                                                                                                                                                   

In Earnings...                                                                                                                                                           

hgi jkl                                                                                                                                                                  

social security number : howareyou                                                                                                                                       

Company Name : bjjs                                                                                                                                                      

Hours : 20 Earnings :15

 Please code using C# Review Figure 12.4 below Create a class called Volunteerthat inherits from the Employee class in Figure 12.4. (Note that Employee is an ab
 Please code using C# Review Figure 12.4 below Create a class called Volunteerthat inherits from the Employee class in Figure 12.4. (Note that Employee is an ab
 Please code using C# Review Figure 12.4 below Create a class called Volunteerthat inherits from the Employee class in Figure 12.4. (Note that Employee is an ab

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site