using System; using System.Collections.Generic; using System.Text; namespace TipExample { /**************************** * this class takes two arguments in with * the cconstructor, the amount the tip is based * on and the percent the user wishes to tip * it calculates the tip and the total due including * the tip * Steve Conger 10/29/2008 * *******************************/ class Tip { //the constructor public Tip(double amt, double pct) { //assign the parameters to the //properties Amount = amt; Percent = pct; } private double amount; public double Amount { get { return amount; } set { amount = value; } } private double percent; //with percent we test the value //if it is less than zero we set it to //zero, if it is greater than zero then //we test wether it is >= to one //if it is we divide it by 100 //to turn it into a decimal //otherwise we leave it as it is public double Percent { get { return percent; } set { //the outer test: is it 0 or more if (value >= 0) { //inner test is it a decimal or //a whole number if (value >= 1) { value /= 100; percent = value; } //end inner if else { percent = value; }//end inner else } //end outer if else // else for outer if { percent = 0; } }//end set }// end property public double CalculateTip() { return Amount * Percent; } public double CalculateTotal() { double tipAmount = CalculateTip(); return Amount + tipAmount; } } }