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

How does the type system works when there is interoperability between a COM and .Net, i mean what exactly happens there

0 Answers   247Customer,


In OB52 , How to define two open posting period, Like only 5 and 8 posting should be open.. should not open 6 and 7..period..

0 Answers  


What do you mean by an array ? explain with an example

7 Answers  


what is the difference between uservariables and systemvariables (in Environmental variables)???

0 Answers  


what is the difference between java , sap ,.net , orecle apps ?

1 Answers  






what are resources in case of Threads

0 Answers   Satyam,


I m Abdullah Ansari compleated MCA from Jamia Hamdard,i have appeared the test of IBM on 2 august at oxford college of engineering Bangalore.waiting for hr round.. This is the first round for IBM.02/08/08 Paper consists of 4 sections 15 questions from matrices(time very less but no negative marking). 25 questions from series completion section (this section is very easy but negative marking) 15 questions from aptitude(little bit tough time limit 15 minute negative marking) 4th section is from computer science (c,c++,operating system,digital electronics ,basic question..) result came at 3 o'clock.i was selected... In interview they asked questions like 1 they asked about final yr project.. 2 what are dynamic and static memory location? 3 linked list and array difference between them. 4 what is function ? what is difference betwen function and inline function? 5 about structure 6 about binary tree, traversal, call by value. 7 storage class and many more basic questions..

0 Answers   IBM,


Write a pascal program to calculate the sum of the first 100 even number and odd number

0 Answers  


what do you man by firmware

4 Answers  


What are two of your strengths that you will bring to our QA/testing team?

0 Answers  


My Qualification is MCA.My interview is on 5th may.They may ask q as------AS u r MCA...Why u r not tring anywhere else? What can be the ans?

0 Answers   State Bank Of India SBI,


Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fit" instead of the number and for the multiples of five print "Bit". For numbers which are multiples of both three and five print "FitBit".

0 Answers  


Categories