public static void ProcessDonation(Donor D) { Console.WriteLine( Console.Out.NewLine + "You have donated (additional): £" + D.DonationAmount.ToString() + Console.Out.NewLine + "The current VAT is: " + D.Vat.ToString() + "%" + Console.Out.NewLine + "Percentage of event supplement added to gift aid is: " + D.EventDonationSupplement + "%" + Console.Out.NewLine + "We made an additional: £" + D.GiftAidAmount + " through our gift aid." + Console.Out.NewLine + "You have donated a total of: £" + D.TotalDonationAmount + "." + Console.Out.NewLine + "Thank you for your generous donation." ); Console.WriteLine("Make another donation? y/n"); if (Console.ReadLine().ToString().ToLower() == "y") { Reset(D); } else { Quit(D); } }
public void Pass() { string s = AppDomain.CurrentDomain.BaseDirectory; Donor D = new Donor(); DonorCalculator.SetDonationAmount(D); Assert.True(true); }
public static void YesNo(char choice, Donor D) { if (choice == 'd') { Dictionary<string, decimal> Events = new Dictionary<string, decimal>(); Events.Add("running", 5.0m); Events.Add("swimming", 3.0m); Events.Add("other", 0.0m); Console.WriteLine("Donate to an event? y/n"); if (Console.ReadLine().ToString().ToLower() == "y") // Donate to event { Console.WriteLine("What even do you want to donate to?"); string Event = Console.ReadLine().ToString(); if (Events.ContainsKey(Event)) { var qEvents = from e in Events where e.Key == Event select e; Console.WriteLine("Please Enter donation amount:"); D.GiftAidAmount += GiftAidAmount(decimal.Parse(Console.ReadLine()), D, qEvents, Event); ProcessDonation(D); } else // Doesn't recognise string { Console.WriteLine("Not a recognised command?"); Reset(D); } } else // Regular donation { Console.WriteLine("Please Enter donation amount:"); D.GiftAidAmount += GiftAidAmount(decimal.Parse(Console.ReadLine()), D); ProcessDonation(D); } } }
static decimal GiftAidAmount(decimal donationAmount, Donor D) { // assign 0 because no event sponsored. D.EventDonationSupplement = 0; // How much donated. D.DonationAmount = donationAmount; // Add old total with new total D.TotalDonationAmount += D.DonationAmount; // Work out gift aid based on VAT var gaRatio = D.Vat / (100 - D.Vat); // Total Gift * TotalDonation. If another donation is made the totals change return Math.Round((Decimal)D.DonationAmount * gaRatio, 2); // Return gift aid }
// 1 public static void SetDonationAmount(Donor D) { YesNo('d', D); }
public static void Reset(Donor D) { SetDonationAmount(D); }
public static Donor Quit(Donor D) { return D; }
static decimal GiftAidAmount(decimal donationAmount, Donor D, IEnumerable<KeyValuePair<string,decimal>> Events, string Event) { // How much donated. D.DonationAmount = donationAmount; // Assign supplement percentage D.EventDonationSupplement = Events.ElementAt(0).Value; // Add old total with new total. This is how much donated. No gift aid calc here D.TotalDonationAmount += D.DonationAmount; // Work out gift aid based on VAT var gaRatio = D.Vat / (100 - D.Vat); // add and assign 5% of gaRatio to gaRatio gaRatio += (gaRatio / 100) * 5; // Total Gift * TotalDonation. If another donation is made the totals change return Math.Round((Decimal)D.DonationAmount * gaRatio, 2); // Return gift aid }
static void SelectUser(string value) { string[] ValidCmds = new String[] { "reset", "quit", "donor", "sa", "options" }; var q = from cmds in ValidCmds where cmds == value select cmds; if (q.Contains(value)) { switch (value.ToLower()) { case "reset": Reset(); break; case "quit": Quit(); break; case "donor": Donor D = new Donor(); DonorCalculator.SetDonationAmount(D); Console.WriteLine("Quit application? y/n"); if (Console.ReadLine().ToLower().ToString() == "y") { Quit(); } else { Reset(); } break; case "sa": SiteAdministrator SA = new SiteAdministrator(); SiteAdministration.SetVat(SA); Console.WriteLine("Quit application? y/n"); if (Console.ReadLine().ToLower().ToString() == "y") { Quit(); } else { Reset(); } break; case "options": Console.WriteLine( Console.Out.NewLine + "This is the Gift Aid Calculator. You can use this appplication by typing your username. See below for list of options:" + Console.Out.NewLine + "Type 'Donor' to make a donation" + Console.Out.NewLine + "Type 'SA' to administrate the application" + Console.Out.NewLine + "Type 'Quit' to quit application" + Console.Out.NewLine ); goto case "reset"; } } else { Console.WriteLine("This is not a valid command."); Reset(); } }