// This is written in C# using visual studio 2015, the book it is basing the fig
ID: 3591362 • 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 or if you have the 5th edition it is figure 11.8 or 11.9. PLEASE BASE THIS ANSWER OFF OF THE BOOK'S FIGURE,THE FIGURE HAS A CODE IN IT THAT SHOULD BE USED WHEN CREATING THE REST OF THE PROGRAM,PLEASE USE THAT CODE AND GIVE THE EXACT OUTPUTS IT IS ASKING FOR. //Please show all steps and comment out what was done.
Create a class called Woodmaker that inherits from the CommissionEmployee class in Figure 11.10 In your Woodmaker 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. Woodmaker 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 Woodmaker 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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class CommisionEmployee
{
private string firstName;
private string lastName;
private string socialsecuritynumber;
private double grossSale;
private double commissionRate;
public CommisionEmployee(string first,string last,string ssn,double grossSale, double commissionRate)
{
this.firstName = first;
this.lastName = last;
this.socialsecuritynumber = ssn;
this.grossSale = grossSale;
this.commissionRate = commissionRate;
}
//get methods
public double getGrossSale()
{
return grossSale;
}
public double getCommissionRate()
{
return commissionRate;
}
public string FirstName
{
get
{
return firstName;
}
}
public string LastName
{
get
{
return lastName;
}
}
public string SocialSecurityNumber
{
get
{
return socialsecuritynumber;
}
}
public double GrossSales
{
get
{
return grossSale;
}
set
{
if (value >= 0)
grossSale = value;
else
throw new ArgumentOutOfRangeException("GrossSales", value, "GrossSales must be >=0");
}
}
public double CommissionRate
{
get
{
return commissionRate;
}
set
{
if ((value > 0) && (value < 1))
commissionRate = value;
else
throw new ArgumentOutOfRangeException("CommissionRate", value, "CommissionRate must be >0 and <1");
}
}
public virtual double Earnings()
{
return commissionRate * grossSale;
}
public override string ToString()
{
return string.Format("{0}:{1} {2} {3}: {4} {5}: {6:C} {7}:{8:f2}", "commission employee", firstName, lastName, "social security number", socialsecuritynumber, "gross Sales", grossSale, "commission rate", commissionRate);
}
};
class WoodDesigner : CommisionEmployee
{
private string firstname;
private string lastname;
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 sos,string first,string last, string skillLevel)
: base(first,last,sos,grossSale, commissionRate)
{
this.firstname = first;
this.lastname = last;
this.skillLevel = skillLevel;
}
public override double Earnings() //calculate earnings
{
if (SkillLevel == "experienced")
return (500 + getGrossSale() * getCommissionRate());
else if (SkillLevel == "apprentice")
return (250 + getGrossSale() * getCommissionRate());
else return 0;
}
};
namespace TestClass
{
class Program
{
static void Main(string[] args)
{
WoodDesigner carpenter1 = new WoodDesigner(5000, 0.32,"111", "John","san", "experienced");
Console.WriteLine("Earnings of carpenter 1 : $" + carpenter1.Earnings());
WoodDesigner carpenter2 = new WoodDesigner(5000, 0.32,"222", "John", "marco","apprentice");
Console.WriteLine("Earnings of carpenter 2 : $" + carpenter2.Earnings());
Console.ReadLine();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.