VS2015 (C#) Create an application that will accept sales information and calcula
ID: 3671888 • Letter: V
Question
VS2015 (C#) Create an application that will accept sales information and calculate the total commissions for a realtor. Commissions are based on the price of the house sold. Sale price: Commission percent < $100K 5% $100K to $250K 6% >$250K 7% Commission is calculated as sales price *commission %. The application should use a sentinel controlled loop to prompt the user for home sales prices for a realtor. Identify the correct commission for each house then Calculate the commission for the sales rep. Test with sets of data for at least 3 sales reps. Output the sales rep commission for each of the sales and the total of all commissions.
Explanation / Answer
SalesRep.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesignPatterns.Composite
{
class SalesRep: iParty
{
public int CommissionPercentage { get; set; }
public int Commission { get; set; }
public string Name { get; set; }
public SalesRep(string name, int commissionPercentage)
{
Name = name;
CommissionPercentage = commissionPercentage;
}
public void SetCommission(int commission)
{
Console.WriteLine("{0} gets {1} commission for his/her {2} percentage", Name, Commission, CommissionPercentage);
}
}
}
SalesTeam.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesignPatterns.Composite
{
class SalesTeam: iParty
{
public List<iParty> AllParties { get; set; }
public int CommissionPercentage { get; set; }
public int Commission { get; set; }
public string Name { get; set; }
public SalesTeam()
{
AllParties = new List<iParty>();
}
public void SetCommission(int commission)
{
foreach (iParty sales in AllParties)
{
sales.Commission = commission * sales.CommissionPercentage / 100;
sales.SetCommission(sales.Commission);
}
}
}
}
iparty.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesignPatterns.Composite
{
public interface iParty
{
int CommissionPercentage { get; set; }
int Commission { get; set; }
void SetCommission(int commission);
}
}
CompositePattern.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesignPatterns.Composite
{
public class CompositePattern
{
public static void RunCompositePattern()
{
Console.WriteLine("Composite Pattern: Composite lets clients treat individual objects and compositions of objects uniformkly. Uses when you are dealing with groups or collections.");
int totalCommision = 1000000;
Console.WriteLine("The sales team are going to split {0} dollar bonus based on each one's percentage. ", totalCommision);
SalesRep Tier2_Joe = new SalesRep("Tier2_Joe", 50);
SalesRep Tier2_John = new SalesRep("Tier2_John", 50);
SalesTeam Tier2Consulting = new SalesTeam { Name = "JJ Tier2Consulting", AllParties = { Tier2_Joe, Tier2_John }, CommissionPercentage = 40 };
SalesRep Tier1_Ryan = new SalesRep("Tier1_Ryan", 30);
SalesRep Tier1_Rich = new SalesRep("Tier1_Rich", 30);
SalesTeam Tier1Consulting = new SalesTeam { Name = "JJ Tier1Consulting", AllParties = { Tier1_Ryan, Tier1_Rich, Tier2Consulting }, CommissionPercentage = 25 };
SalesRep Alex = new SalesRep("Alex", 25);
SalesRep Isabel = new SalesRep("Isabel", 25);
SalesRep Michelle = new SalesRep("Michelle", 25);
SalesTeam everyone = new SalesTeam { AllParties = { Alex, Isabel, Michelle, Tier1Consulting }, CommissionPercentage = 100 };
everyone.SetCommission(totalCommision);
Console.ReadLine();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.