Question: I am attempting to have the the following program validate the data inputted for base pay and annual salary. I want to ensure a dollar
I am attempting to have the the following program validate the data inputted for base pay and annual salary. I want to ensure a dollar amount is entered and the value is not negative. The requirement is:
If any of the inputs are unreasonable, tell user with a message and force reentry of the data (e.g. Negative Sales, Annual Salary > $120,000 or < $12,000, if not 0).
I have entered this line of code to meet the requirement but it is not working: while(double.TryParse( inValue, out basePay) == false) { WriteLine ("Invalid input"); Write("Please re-enter a dollar amount."); inValue = ReadLine(); } The following is the class and main: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; namespace Employee { class EmployeePay { //Data members, data fields, or characteristics private string employeeFirstName; private string employeeLastName; private double basePay; private double sales; private double netSales; //constructor with five data members public EmployeePay(string first, string last, double salary, double commissionBase, double net) { employeeFirstName = first; employeeLastName = last; basePay = salary; sales = commissionBase; netSales = net; } //constructor with three data memebers public EmployeePay(string first, string last, double salary) { employeeFirstName = first; employeeLastName = last; basePay = salary; } //constructor with two data memebers public EmployeePay(string first, string last) { employeeFirstName = first; employeeLastName = last; } //default constructor public EmployeePay() { } //property to change employee first name public string EmployeeFirstName { get { return employeeFirstName; } set { employeeFirstName = value; } } public string EmployeeLastName { get { return employeeLastName; } set { employeeLastName = value; } } public double BasePay { get { return basePay; } set { basePay = value; } } public double Sales { get { return sales; } set { sales = value; } } // Calculate monthly pay public double CalculateBasePay() { basePay = basePay / 12; return basePay; } //Calculate netSales public double CalculateNetSales() { netSales = sales - (10 * basePay); return netSales; } //Calculate Gross Pay public double CalculateGrossPay() { return CalculateBasePay() + CalculateCommission(); } //Calculate Commission public double CalculateCommission() { const double TIER_ONE = .05; // commission rate for or less $10,000 const double TIER_TWO = .1; // commission rate for $15,000 -$24,999 const double TIER_THREE = .15; // commission rate for $25,000 -$49,999 const double TIER_FOUR = .20; // commission rate for sale over $50,0000 double commission; //commission double netSales = CalculateNetSales(); if (netSales <= 0) return (commission = 0); else if ((netSales >= 10000) && (netSales < 10001)) return (commission = (netSales* TIER_ONE)); //commission rate for between $1 and $10,000 else if ((netSales > 10001) && (netSales<=25000)) return (commission = (netSales-10000) * TIER_TWO + 500); //commission rate for between $10,000 and $25,000 else if ((netSales > 25000) && (netSales < 50000)) return (commission = (netSales - 25000) * TIER_THREE + 2000); //commission rate for between $25,000 and $49,999 else return (commission = (netSales -50000) * TIER_FOUR + 5750 );//commission rate for over $50,000 } public override string ToString() { return employeeFirstName + " " + employeeLastName + "Base Salary:" + CalculateBasePay().ToString("C") + "Sales:" + Sales + "Commission :" + CalculateCommission().ToString("C") + "Gross Pay:" + CalculateGrossPay().ToString("C"); } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; namespace Employee { class Program { //Here is List of type Employee pay static List
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
