Building Quotation engine program

Answers were Sorted based on User's Feedback



Building Quotation engine program..

Answer / perfdev

TravelInsuranceQuoteTests --> DataLayer --> CustomerPremiumTests.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Core;
using NUnit.Framework;
using TravelInsuranceQuote.DataLayer;

namespace TravelInsuranceQuoteTests.DataLayer
{
[TestFixture]
public class CustomerPremiumTests
{
[Test]
public void CustomerPremium_CanCreateObject()
{
var customerPremium = new CustomerPremium();
Assert.That(customerPremium, Is.Not.Null);
Assert.That(customerPremium, Is.TypeOf<CustomerPremium>());
}

[Test]
public void CustomerPremium_CanSetProperties()
{
var customerPremium = new CustomerPremium
{
Base = 10.00,
Age = new double[] { 20.00, 4.00 },
Sex = new double[] { 20.00, 4.00 },
Destination = new double[] { 20.00, 4.00 },
TravelPeriod = new double[] { 20.00, 4.00 },
Tax = new double[] { 20.00, 4.00 },
Total = 30.00

};
Assert.That(customerPremium.Base, Is.EqualTo(10.00));
Assert.That(customerPremium.Age[0], Is.EqualTo(20.00));
Assert.That(customerPremium.Sex[1], Is.EqualTo(4.00));
Assert.That(customerPremium.Destination[0], Is.EqualTo(20.00));
Assert.That(customerPremium.TravelPeriod[1], Is.EqualTo(4.00));
Assert.That(customerPremium.Tax[0], Is.EqualTo(20.00));
Assert.That(customerPremium.Total, Is.EqualTo(30.00));
}
}
}

#####################

CustomerTests.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Core;
using NUnit.Framework;
using TravelInsuranceQuote.DataLayer;

namespace TravelInsuranceQuoteTests.DataLayer
{
[TestFixture]
public class CustomerTests
{
[Test]
public void Customer_CanCreateObject()
{
var customer = new Customer();
Assert.That(customer, Is.Not.Null);
Assert.That(customer, Is.TypeOf<Customer>());
}

[Test]
public void Customer_CanSetProperties()
{
var customer = new Customer {
TripType = TripType.Single,
Sex = Sex.Male,
Destination = Destination.Europe,
Age = 20,
TravelPeriod = 1
};
Assert.That(customer.TripType, Is.EqualTo(TripType.Single));
Assert.That(customer.Sex, Is.EqualTo(Sex.Male));
Assert.That(customer.Destination, Is.EqualTo(Destination.Europe));
Assert.That(customer.Age, Is.EqualTo(20));
Assert.That(customer.TravelPeriod, Is.EqualTo(1));
}
}
}

Is This Answer Correct ?    1 Yes 0 No

Building Quotation engine program..

Answer / testndl002

BusinessLayer --> QuoteEngine.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TravelInsuranceQuote.DataLayer;

namespace TravelInsuranceQuote.BusinessLayer
{
public class QuoteEngine
{

public double GetBasePremium(TripType tripType)
{
double basePremium = 0;
switch (tripType)
{
case TripType.Single:
basePremium = 20.00;
break;
case TripType.Annual:
basePremium = 80.00;
break;
}
return basePremium;
}

public double GetAgeRating(int age)
{
if (age <= 18)
{
return 1.2;
}
else if (age <= 45)
{
return 1.0;
}
else if (age <= 55)
{
return 1.2;
}
else if (age <= 65)
{
return 1.8;
}
else if (age <= 70)
{
return 2.0;
}
return 0;
}

public double GetSexRating(Sex sex)
{
double sexRating = 0;
switch (sex)
{
case Sex.Male:
sexRating = 1.2;
break;
case Sex.Female:
sexRating = 0.9;
break;
}
return sexRating;
}

public double GetDestinationRating(Destination destination)
{
double destinationRating = 0;
switch (destination)
{
case Destination.UK:
destinationRating = 0.6;
break;
case Destination.Europe:
destinationRating = 1.0;
break;
case Destination.Worldwide:
destinationRating = 1.4;
break;
}
return destinationRating;
}



public double GetTravelPeriodRating(int days)
{
if (days <= 7)
{
return 0.5;
}
else if (days <= 14)
{
return 0.9;
}
else if (days <= 30)
{
return 1.2;
}
return 0;
}

public double[] GetUpdatedPremium(double premium, double rate)
{
var updatedPremium = new double[2];
updatedPremium[0] = Math.Round((premium * rate), 2);
updatedPremium[1] = Math.Round((updatedPremium[0] - premium), 2);
return updatedPremium;
}

public CustomerPremium GetPremium(Customer customer, out string reason)
{
var customerPremium = new CustomerPremium();
customerPremium.Base = GetBasePremium(customer.TripType);
var ageRating = GetAgeRating(customer.Age);
if (ageRating == 0)
{
reason = "Age";
return null;
}
customerPremium.Age = GetUpdatedPremium(customerPremium.Base, ageRating);
var sexRating = GetSexRating(customer.Sex);
customerPremium.Sex = GetUpdatedPremium(customerPremium.Age[0], sexRating);
var destinationRating = GetDestinationRating(customer.Destination);
customerPremium.Destination = GetUpdatedPremium(customerPremium.Sex[0], destinationRating);
var travelPeriodRating = GetTravelPeriodRating(customer.TravelPeriod);
if (travelPeriodRating == 0)
{
reason = "TravelPeriod";
return null;
}
customerPremium.TravelPeriod = GetUpdatedPremium(customerPremium.Destination[0], travelPeriodRating);
customerPremium.Tax = GetUpdatedPremium(customerPremium.TravelPeriod[0], 1.05);
customerPremium.Total = customerPremium.Tax[0];
reason = string.Empty;
return customerPremium;
}

}
}

Is This Answer Correct ?    0 Yes 0 No

Building Quotation engine program..

Answer / testndl002

DataLayer --> Common.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TravelInsuranceQuote.DataLayer
{
public enum Destination
{
UK,
Europe,
Worldwide
}
public enum TripType
{
Single,
Annual
}
public enum Sex
{
Male,
Female
}
}

#######

DataLayer-->customer.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TravelInsuranceQuote.DataLayer
{
public class Customer
{
public TripType TripType { get; set; }
public int Age { get; set; }
public Sex Sex {get; set;}
public Destination Destination {get; set;}
public int TravelPeriod {get; set;}
//public Customer(string Type, string Sex, string Destination, int Age, int Pot)
//{
// Type = "singletrip";
// Sex = "male";
// Destination = "UK";
// Age = 20;
// Pot = 5;
//}
}
}

#########

DataLayer --> CustomerPremium.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TravelInsuranceQuote.DataLayer
{
public class CustomerPremium
{
public double Base { get; set; }
public double[] Age { get; set; }
public double[] Sex { get; set; }
public double[] Destination { get; set; }
public double[] TravelPeriod { get; set; }
public double[] Tax { get; set; }
public double Total { get; set; }
}
}

Is This Answer Correct ?    0 Yes 0 No

Building Quotation engine program..

Answer / testndl002

PresentationLayer --> Program.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TravelInsuranceQuote.DataLayer;
using TravelInsuranceQuote.BusinessLayer;
using System.IO;

namespace TravelInsuranceQuote.PresentationLayer
{
public class Program
{

public static void Main(string[] args)
{
var customer = new Customer();

string[] lines = File.ReadAllLines(@"D:\Test.txt");

foreach (var line in lines)
{
var nameValue = line.Split(new char[] { ':' });
switch (nameValue[0].ToLower())
{
case "triptype":
customer.TripType = ((nameValue[1].ToLower() == "single") ? TripType.Single : TripType.Annual);
break;
case "sex":
customer.Sex = ((nameValue[1].ToLower() == "male") ? Sex.Male : Sex.Female);
break;
case "destination":
customer.Destination = ((nameValue[1].ToLower() == "uk") ? Destination.UK :
((nameValue[1].ToLower() == "europe") ? Destination.Europe : Destination.Worldwide));
break;
case "age":
customer.Age = Convert.ToInt32(nameValue[1]);
break;
case "travelperiod":
customer.TravelPeriod = Convert.ToInt32(nameValue[1]);
break;
}

}

//Console.Write("Type:");
//customer.TripType = ((Console.ReadLine().ToLower() == "single") ? TripType.Single : TripType.Annual);
//Console.Write("Age:");
//customer.Age = int.Parse(Console.ReadLine());
//Console.Write("Sex:");
//customer.Sex = ((Console.ReadLine().ToLower() == "male") ? Sex.Male : Sex.Female); ;
//Console.Write("Destination:");
//switch(Console.ReadLine().ToLower())
//{
// case "uk" :
// customer.Destination = Destination.UK;
// break;
// case "europe" :
// customer.Destination = Destination.Europe;
// break;
// case "worldwide" :
// customer.Destination = Destination.Worldwide;
// break;
//}
//Console.Write("TravelPeriod:");
//customer.TravelPeriod = int.Parse(Console.ReadLine());

string reason;
var customerPremium = new QuoteEngine().GetPremium(customer, out reason);

if (customerPremium != null)
{
Console.WriteLine("BasePremium({0}):{1}", customerPremium.Base, customerPremium.Base);
Console.WriteLine("Age({0}):{1}", customerPremium.Age[1], customerPremium.Age[0]);
Console.WriteLine("Sex({0}):{1}", customerPremium.Sex[1], customerPremium.Sex[0]);
Console.WriteLine("Destination({0}):{1}", customerPremium.Destination[1], customerPremium.Destination[0]);
Console.WriteLine("TravelPeriod({0}):{1}", customerPremium.TravelPeriod[1], customerPremium.TravelPeriod[0]);
Console.WriteLine("Tax({0}):{1}", customerPremium.Tax[1], customerPremium.Tax[0]);
Console.WriteLine("Total:{0}", customerPremium.Total);
}
else
{
Console.Write("Declined:" + reason);
}
Console.ReadKey();
}
}
}

Is This Answer Correct ?    0 Yes 0 No

Building Quotation engine program..

Answer / perfdev

TravelInsuranceQuoteTests --> BusinessLayer -->QuoteEngineTests.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using TravelInsuranceQuote.DataLayer;
using TravelInsuranceQuote.BusinessLayer;

namespace TravelInsuranceQuoteTests.BusinessLayer
{
[TestFixture]
public class QuoteEngineTests
{
[Test]
public void QuoteEngine_CanCreateObject()
{
var quoteEngine = new QuoteEngine();
Assert.That(quoteEngine, Is.Not.Null);
Assert.That(quoteEngine, Is.TypeOf<QuoteEngine>());
}

[Test]
public void GetBasePremium_ValidSingleTripType_ReturnsPremium()
{
var quoteEngine = new QuoteEngine();

var premium = quoteEngine.GetBasePremium(TripType.Single);

Assert.That(premium, Is.EqualTo(20.00));
}

[Test]
public void GetBasePremium_ValidAnnualTripType_ReturnsPremium()
{
var quoteEngine = new QuoteEngine();

var premium = quoteEngine.GetBasePremium(TripType.Annual);

Assert.That(premium, Is.EqualTo(80.00));
}

[Test]
public void GetAgeRating_ValidAgeRange_ReturnsRating()
{
var quoteEngine = new QuoteEngine();

var rating = quoteEngine.GetAgeRating(50);

Assert.That(rating, Is.EqualTo(1.2));
}

[Test]
public void GetAgeRating_HighAgeRange_ReturnsZero()
{
var quoteEngine = new QuoteEngine();

var rating = quoteEngine.GetAgeRating(90);

Assert.That(rating, Is.EqualTo(0));
}

[Test]
public void GetSexRating_InputFemale_ReturnsRating()
{
var quoteEngine = new QuoteEngine();

var rating = quoteEngine.GetSexRating(Sex.Female);

Assert.That(rating, Is.EqualTo(0.9));
}

[Test]
public void GetDestinationRating_InputWorlwide_ReturnsRating()
{
var quoteEngine = new QuoteEngine();

var rating = quoteEngine.GetDestinationRating(Destination.Worldwide);

Assert.That(rating, Is.EqualTo(1.4));
}

[Test]
public void GetTravelPeriodRating_InputValidDays_ReturnsRating()
{
var quoteEngine = new QuoteEngine();

var rating = quoteEngine.GetTravelPeriodRating(10);

Assert.That(rating, Is.EqualTo(0.9));
}

[Test]
public void GetUpdatedPremium_InputPremiumAndRate_ReturnsUpdatedPremiumAndDifference()
{
var quoteEngine = new QuoteEngine();

var updatedPremium = quoteEngine.GetUpdatedPremium(10.00, 2.0);

Assert.That(updatedPremium[0], Is.EqualTo(20.00));
Assert.That(updatedPremium[1], Is.EqualTo(10.00));
}

[Test]
public void GetPremium_InputCustomer_ReturnsCustomerPremium()
{
var quoteEngine = new QuoteEngine();
var customer = new Customer {
TripType = TripType.Single,
Age = 20,
Sex = Sex.Male,
Destination = Destination.Europe,
TravelPeriod = 1
};
string reason;
var customerPremium = quoteEngine.GetPremium(customer, out reason);

Assert.That(customerPremium.Base, Is.EqualTo(20.00));
Assert.That(customerPremium.Age[0], Is.EqualTo(20.00));
Assert.That(customerPremium.Sex[1], Is.EqualTo(4.00));
Assert.That(customerPremium.Destination[0], Is.EqualTo(24.00));
Assert.That(customerPremium.TravelPeriod[1], Is.EqualTo(-12.00));
Assert.That(customerPremium.Tax[0], Is.EqualTo(12.60));
Assert.That(customerPremium.Total, Is.EqualTo(12.60));
Assert.That(reason, Is.EqualTo(string.Empty));
}
}
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Programming Languages AllOther Interview Questions

in IT trend mantis meant what? how to know mantis in IT trends? detail description about mantis?

0 Answers   Sacred Heart College,


Please describe an example where you used object orientation in one of your programs.

0 Answers  


purpose of abstraction and interface

0 Answers  


Code for display the images from drive using vb 6.0?

2 Answers   IBM,


How does the TCP handle the issue of multiplexing?

0 Answers  






Write a shell program where you enter a number which corresponds to K.M. Find out the corresponding values in m, cm, inches, and feet. Hints:- 1 k.m= 1000 m 1 m= 100 cm 1 inches= 2.54 cm. 1 feet= 12 inches

0 Answers  


how to add a new table with variables and thier values into a imported file uisng proc import?

0 Answers  


If i have a dataset queried from Sql and I would like to insert the dataset into a specific node in an xml document how do I do this

0 Answers   SGT,


Outline the two important features of a terminating recursion. Any ideas?

0 Answers  


plz send me NIC Scientific Officer /Engineer-SB(Programmer) previous question paper or syllabus

2 Answers   NIC,


What parameters are used to run a JCL JOB on a perticular DAY and TIME and DATE

1 Answers  


In JCl , we have COND parameter.This holds comparison code and condition.It also has only and even parameters. ex: COND((4,GE),EVEN).what the comma mean here. is that 'and' or 'or'.

0 Answers   L&T,


Categories