Question

In: Computer Science

At the moment, AmSure Insurance Agency distributes exciting Life Insurance Products, Health Insurance Products and Motor Insurance Products.

USE C#  

Maximum used policy

At the moment, AmSure Insurance Agency distributes exciting Life Insurance Products, Health Insurance Products and Motor Insurance Products. The company wants to find the policy type that has maximum number of users. Given a CSV file with all the policy details that are availed through Amsure, Write a program to find the policy type which has maximum users using LINQ statements.

Create a class Policy which include following attributes,

Data TypeVariable Name
int_policyNumber
string_insuranceType
DateTime_startDate
DateTime_renewalDate


Include appropriate Properties as follows.
private string _name;
public string Name
{
    get { return _name; }
    set { _name = value; }
}
Create the policy.csv file which contain the policy details (ie) policy number, insurance type, policy start date and policy renewal date which is separated by comma.
Create a program class. Read the policy.csv file and store it into the policy list. Write a LINQ query to find the policy type under which maximum policies are there.

Input and Output Format:
Input consists of policy.csv file.
Output should display the policy type under which maximum policies are there.

Sample input and output :
Input file policy.csv contain the details as follows,
6435,Home Insurance,01-03-2016,10-07-2017
5234,Health Insurance,12-12-2014,06-01-2019
5614,Health Insurance,02-09-2015,03-11-2019
8575,Motor Insurance,07-11-2011,03-12-2017
8541,Health Insurance,01-11-2015,07-12-2016
4526,Motor Insurance,05-01-2017,13-09-2018
Output :
Health Insurance

Solutions

Expert Solution

Updated policy.csv file path.

Also update date time format if required, It Is dd-MM-yyyy for now according to the test data provided.

Please find code in bold.

// Program.cs

using System;
using System.IO;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            List policyList = new List();

            // Read all lines from file in string array
            string[] lines = File.ReadAllLines(@"C:\WorkSpace\Chegg\policy.csv");

            foreach (var line in lines)
            {
                string[] values = line.Split(',');

                Policy policy = new Policy();
                policy.PolicyNumber = Convert.ToInt32(values[0]);
                policy.InsuranceType = values[1];
                policy.StartDate = DateTime.ParseExact(values[2], "dd-MM-yyyy", CultureInfo.InvariantCulture);
                policy.RenewalDate = DateTime.ParseExact(values[3], "dd-MM-yyyy", CultureInfo.InvariantCulture);

                policyList.Add(policy);
            }

            // LinQ statement to get most insured policy type
            var pl = policyList
                     .GroupBy(p => p.InsuranceType)
                     .OrderByDescending(x => x.Count())
                     .FirstOrDefault();

            Console.WriteLine(pl.Key);
            Console.Read();
        }
    }
}

// Policy.cs

using System;

namespace ConsoleApp
{
    public class Policy
    {
        private int _policyNumber;
        private string _insuranceType;
        private DateTime _startDate;
        private DateTime _renewalDate;

        public int PolicyNumber
        {
            get { return _policyNumber; }
            set { _policyNumber = value; }
        }
        public string InsuranceType
        {
            get { return _insuranceType; }
            set { _insuranceType = value; }
        }
        public DateTime StartDate
        {
            get { return _startDate; }
            set { _startDate = value; }
        }
        public DateTime RenewalDate
        {
            get { return _renewalDate; }
            set { _renewalDate = value; }
        }
    }
}


Related Solutions

Write about any five features/benefit of Health and Motor Insurance.
Write about any five features/benefit of Health and Motor Insurance.
Comprehensive Insurance Company has two products lines: health insurance and auto insurance. The two products lines...
Comprehensive Insurance Company has two products lines: health insurance and auto insurance. The two products lines are served by three operating departments which are necessary for providing the two types of products: claims processing, administration, and sales. These three operating departments are supported by two departments: information technology and operations. The support provided by information technology and operations to the other department is shown below. Support Departments Operating Departments IT Operations Claims Processing Administration Sales IT 20% 20% 40% 20%...
A 55-year old buys a continuous increasing whole life insurance. The benefit payable at the moment...
A 55-year old buys a continuous increasing whole life insurance. The benefit payable at the moment of death (time t) is equal to bt=1000t. Mortality is DeMoivre, with ω=100;δ=0.06 Find the Net Single Premium of this insurance.
Why life insurance doesn’t have deductible while health insurance have?
Why life insurance doesn’t have deductible while health insurance have?
When calculating premiums on life insurance products insurance companies often use life tables which enable the...
When calculating premiums on life insurance products insurance companies often use life tables which enable the probability of a person dying in any age interval to be calculated. The following table gives the number out of 100,000 females who are still alive during each five-year period of life between the age of 20 to 60 (inclusive): Out of 100,000 females born                         Exact age (years)                                          Number alive at exact age 20                                                                                                99,150 25                                                                                                 98,983 30                                                                                           ...
A manager for an insurance company believes that customers have the following preferences for life insurance products:
A manager for an insurance company believes that customers have the following preferences for life insurance products: 30% prefer Whole Life, 30% prefer Universal Life, and 40% prefer Life Annuities. The results of a survey of 330 customers were tabulated. Is it possible to refute the sales manager's claimed proportions of customers who prefer each product using the data? Product Number Whole 109 Universal 96 Annuities 125   Step 1 of 10: State the null and alternative hypothesis. Answer  ...
life and health insurance 3. which of the following is not a requirement of a qualified...
life and health insurance 3. which of the following is not a requirement of a qualified plan? 4. under the one-year term dividends option the dividends is used to buy term covers for a year with the amount of term coverage usually limited to the ? 5. which of the following is true about agents life insurance? sales advertisement in sate? 6. which is one of the factors that determines life premiums? 10. which rider allows the policyowner to increase...
Discuss the reasons that employers provide their employees benefits (health insurance, life insurance, pension benefits) in...
Discuss the reasons that employers provide their employees benefits (health insurance, life insurance, pension benefits) in addition to monetary compensation.
Your organization currently offers health insurance, dental insurance, life insurance, a 401(k) retirement program, and paid...
Your organization currently offers health insurance, dental insurance, life insurance, a 401(k) retirement program, and paid vacation. Due to budget cuts, the company must cut one program in total. Which program would you cut, and why?
Fund Life & Health insurance How does the law of insurable interest protect human life? (identifying...
Fund Life & Health insurance How does the law of insurable interest protect human life? (identifying the requirement of the law and insurance company and analyzing how it protects general public.) What factors make joint life an effective tool in the case of a buy-sell agreement? ( Explain how JL matches the need for buy-sell agreement timing and analyzing what riders in JL benefits in the situation of buy-sell agreement.)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT