// This is written in C# using visual studio 2015, the book it is basing the fig
ID: 3590161 • Letter: #
Question
// This is written in C# using visual studio 2015, the book it is basing the figure 11.10 off of is Visual C# How To Program, Deitel H.M, Deitel, P.J 6th Edition
//Please show all steps and comment out what was done
Create a class called Wooddesigner that inherits from the CommissionEmployee class in Figure 11.10 In your Wooddesigner class, Earnings() should calculate the fee earned for a carpentry job. Gross sales represents the amount charged to a customer and commission rate represents the % that a particular carpenter earns. Wooddesigner Earnings is calculated as the skill level base rate + amount charged * commission rate. Skill level base rate is $500 for an experienced carpenter and $250 for an apprentice.
Your class should contain a constructor that inherits from the CommissionEmployee class and initializes the instance variables. The Wooddesigner class should add an instance variable for the name of the customer where the carpentry service occurred. Also add an instance variable to represent skill level. Create a property for them also.
Create a second class that prompts the user for the information for two carpenters, creates the 2 two carpenters objects, then displays each two carpenters. One carpenter should be experienced and one should be an apprentice.
Explanation / Answer
using System;
class CommisionEmployee //base class
{
private double grossSale;
private double commissionRate;
public CommisionEmployee(double grossSale,double commissionRate)//argument constructor
{
this.grossSale = grossSale;
this.commissionRate = commissionRate;
}
//get methods
public double getGrossSale()
{
return grossSale;
}
public double getCommissionRate()
{
return commissionRate;
}
};
class WoodDesigner : CommisionEmployee //derived class
{
private double grossSale;
private double commissionRate;
private string customerName;
private string skillLevel;
//properties
public string SkillLevel
{
get{ return skillLevel;}
set{ skillLevel = value;}
}
//passing arguments to base class constructor
public WoodDesigner(double grossSale,double commissionRate,string customerName,string skillLevel): base(grossSale,commissionRate)
{
this.customerName = customerName;
this.skillLevel = skillLevel;
}
public double Earnings() //calculate earnings
{
if(SkillLevel == "experienced")
return (500 + getGrossSale()*getCommissionRate());
else if(SkillLevel == "apprentice" )
return (250 +getGrossSale()*getCommissionRate());
else return 0;
}
};
public class Test
{
public static void Main()
{
WoodDesigner carpenter1 = new WoodDesigner(45655,0.04,"Harry Lewis","experienced");
Console.WriteLine("Earnings of carpenter 1 : $"+ carpenter1.Earnings());
WoodDesigner carpenter2 = new WoodDesigner(45655,0.045,"Harry Lewis","apprentice");
Console.WriteLine("Earnings of carpenter 2 : $"+ carpenter2.Earnings());
}
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.