示例#1
0
        public double CalculatePremium(InsuranceBasis basis)
        {
            double netPremium = 0.0;

            double basePremium = _provider.GetBasePremium(basis.Type);
            GenerateOutput("BasePremium", basePremium,  ref netPremium);

            double ageRating = _provider.GetRating("Age",basis.Age);
            double premiumChange = CalculatePremiumChange(netPremium, ageRating);
            GenerateOutput("Age", premiumChange, ref netPremium);

            double sexRating = _provider.GetRating("Sex", basis.Sex);
            premiumChange = CalculatePremiumChange(netPremium, sexRating);
            GenerateOutput("Sex", premiumChange, ref netPremium);

            double destinationRating = _provider.GetRating("Destination", basis.Destination);
            premiumChange = CalculatePremiumChange(netPremium, destinationRating);
            GenerateOutput("Destination", premiumChange, ref netPremium);

            double travelPeriodRating = _provider.GetRating("TravelPeriod", basis.TravelPeriod);
            premiumChange = CalculatePremiumChange(netPremium, travelPeriodRating);
            GenerateOutput("PeriodOfTravel", premiumChange, ref netPremium);

            return netPremium;
        }
        public InsuranceBasis Read(string inputFile)
        {
            InsuranceBasis basis = new InsuranceBasis();
            try
            {
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader(inputFile))
                {
                    String line;
                    // Read and display lines from the file until the end of
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] inputs = line.Split(':');

                        switch (inputs[0])
                        {
                            case "Type":
                                basis.Type = (InsuranceType) Enum.Parse(typeof(InsuranceType), inputs[1]);
                                break;
                            case "Age":
                                basis.Age = Convert.ToInt16(inputs[1]);
                                break;
                            case "Sex":
                                basis.Sex = inputs[1];
                                break;
                            case "Destination":
                                basis.Destination = inputs[1];
                                break;
                            case "PeriodOfTravel":
                                basis.TravelPeriod = Convert.ToInt32(inputs[1]);
                                break;
                        }
                    }
                }

                return basis;
            }
            catch (Exception e)
            {
                throw new Exception(string.Format("Error occured while reading the file: {0}", inputFile), e);
            }
        }