In: Computer Science
USE C#.
Write an AutoInsurance class to abstract auto insurance polices. Each auto insurance policy contains policy holder's name, policy number, car model, monthly premium, inception date, and expire date. This class needs to provide two constructors and one method which is to calculate the yearly premium.
using System;
namespace InsuranceApplication
{
class AutoInsurancePolicy
{
private string
policyHolderName;
private long policyNumber;
private string carModel;
private double
monthlyPremium;
String inceptionDate;
String expiryDate;
public
AutoInsurancePolicy()
{
Console.WriteLine("Object is being created");
}
public
AutoInsurancePolicy(string name, long number, string model, double
premium, String inception, String expiry)
{
policyHolderName
= name;
policyNumber =
number;
carModel =
model;
monthlyPremium =
premium;
inceptionDate =
inception;
expiryDate =
expiry;
}
public double
calculateYearlyPremium()
{
return
monthlyPremium*12;
}
}
class AutoInsurance
{
static void Main(string[]
args)
{
AutoInsurancePolicy policy = new
AutoInsurancePolicy("Aakash",123,"abcc",125.00,"12/06/2016","12/06/2020");
Console.WriteLine("Yearly Premium : {0}",
policy.calculateYearlyPremium());
AutoInsurancePolicy policy1 = new
AutoInsurancePolicy("Aakash",1222,"abcc",250.00,"12/06/2016","12/06/2020");
Console.WriteLine("Yearly Premium : {0}",
policy1.calculateYearlyPremium());
}
}
}
Sample Output :
Yearly Premium : 1500 Yearly Premium : 3000