Design a solution that prints the amount of pay a commissioned salesperson takes home. The more sales documented, the larger the commission rate. Allow the user to input a total sales amount for the week. Compute the commission based on the following table. Display the pay amount formatted with commas, decimals, and a dollar symbol.
less than $ 1000: 3%
$ 1001–$ 5000: 5%
$ 5001–$ 10000: 6%
over $ 10000: 7%
Be sure to design your solution so that all possible situations are accounted for and tested. What values did you enter and test to verify your program’s correctness?
1
Expert's answer
2015-10-12T03:35:30-0400
using System;
namespace Salesperson { class Program { static void Main(string[] args) { Console.Write("Enter documented sales amount for this week: "); string input = Console.ReadLine(); try { double amount = Double.Parse(input); Salesperson p = new Salesperson(); Console.WriteLine("Salesperson gets {0:N} $", p.CalculateSalesPersonProfit(amount)); } catch (FormatException) { Console.WriteLine("Input contains ivalid charaters"); } catch (ArgumentException) { Console.WriteLine("Invalid sales amount"); } catch (Exception) { Console.WriteLine("Program was terminated unexpectedly"); } //To let user see the result Console.ReadKey(); } }
class Salesperson { public double CalculateSalesPersonProfit(double salesAmount) { if (!checkInput(salesAmount)) throw new ArgumentException("Invalid input"); if (salesAmount >= 0 && salesAmount <= 1000) return salesAmount * 0.03; else if (salesAmount <= 5000) return salesAmount * 0.05; else if (salesAmount <= 10000) return salesAmount * 0.06; else return salesAmount * 0.07; }
Comments
Leave a comment