}//End btnSubmit_Click /************************************************ * EXPECTS: The Hunter * RETURNS: Returns A Bool * TASKS: Evaluate the number of animals checked * Vs. the number hunted. Then returns true or * false depending on the outcome. ************************************************/ public bool NumAnimalsValid(Hunter theHunter) { double numAnimalsChecked = 0; //Adds up the number boxes and gets a total numAnimalsChecked += (double)numUpDnWildebeest.Value; numAnimalsChecked += (double)numUpDnBuffalo.Value; numAnimalsChecked += (double)numUpDnZebra.Value; numAnimalsChecked += (double)numUpDnImpala.Value; numAnimalsChecked += (double)numUpDnGemsbok.Value; numAnimalsChecked += (double)numUpDnWarthog.Value; numAnimalsChecked += (double)numUpDnHippo.Value; //Compares the total to the number of animals the hunter said he was hunting if (numAnimalsChecked == theHunter.AnimalsHunted) { lblMessage.Text = ""; return(true); } else { lblMessage.Text = "The Number Of Animals You Checked Do Not Equal The Animals Hunted!"; return(false); } //End if / else } //End NumAnimalsValid
/************************************************ * EXPECTS: A button press * RETURNS: Nothing * TASKS: Submit the users data and generate a bill ************************************************/ private void btnSubmit_Click(object sender, EventArgs e) { //Creating an instance of the hunter Hunter theHunter = new Hunter(txtBxFName.Text, txtBxLName.Text, (double)numUpDnDaysHunting.Value, (double)numUpDnAnimalsHunted.Value); //Validate the Animals hunted against the number checked if (NumAnimalsValid(theHunter) == true) { //The hunter is valid so calculate the price CalcPrice(theHunter); btnReset.Visible = true; } //End if } //End btnSubmit_Click
} //End NumAnimalsValid /************************************************ * EXPECTS: The Hunter * RETURNS: Nothing * TASKS: Calculate the price of the safari ************************************************/ public void CalcPrice(Hunter theHunter) { double discountPercent = 0; double finalTotal = 0; double huntDaysCost = 0; double costBeforeDis = 0; double discountAmt = 0; double tip = 0; //Check how many animals the hunter checked and gets total price Tuple <int, int> tuple = AnimalsChecked(); //Calculate the cost of hunting days huntDaysCost = CalcCostOfHuntingDays(theHunter, tuple.Item1); //Set Cost before discount costBeforeDis = tuple.Item2 + huntDaysCost; txtBxCostB4Dis.Text = "$" + Convert.ToString(costBeforeDis); //Calculate discounts if (tuple.Item1 == 7) { discountPercent = 0.05; txtBxDisAmt.Text = "5%"; //Calculate the tip cost discountAmt = (huntDaysCost + tuple.Item2) * discountPercent; tip = (((huntDaysCost + tuple.Item2) - discountAmt) * 0.14); txtBxTip.Text = Convert.ToString(tip); } else { txtBxDisAmt.Text = "0%"; //Calculate the tip cost tip = (huntDaysCost + tuple.Item2) * 0.14; txtBxTip.Text = tip.ToString("c"); }//End if / else //Set cost of hunting days on the form txtBxCostHuntDays.Text = "$" + Convert.ToString(huntDaysCost); //Calculate the final total finalTotal = ((huntDaysCost + tuple.Item2) - discountAmt) + tip; txtBxFinalTotal.Text = "$" + Convert.ToString(finalTotal); }//End CalcPrice
}//End CalcPrice /************************************************ * EXPECTS: The Hunter, and the numberOfANimalsChecked * RETURNS: A double * TASKS: Calculate the cost of hunting days and * give free days if they hunt a certain amount * of animals. ************************************************/ public double CalcCostOfHuntingDays(Hunter theHunter, int numAnimalsChecked) { double costOfHuntDays = 0; double huntDaysFree = 0; if (numAnimalsChecked >= 5) { huntDaysFree = 840; } else if (numAnimalsChecked >= 3 && numAnimalsChecked < 5) { huntDaysFree = 600; }//End if / else costOfHuntDays = (theHunter.DaysHunted * 120) - huntDaysFree; if (costOfHuntDays <= 0) { return(0); } else { return(costOfHuntDays); } //End if / else } //End CalcCostOfHuntingDays