Question

In: Computer Science

Can someone please provide C# code in Events,Delegates and Reflection for the below problem. ----------------- Agent-Policy...

Can someone please provide C# code in Events,Delegates and Reflection for the below problem.

-----------------

Agent-Policy

XYZ Assurance wants to categorize the policies based on the agent who sold the policy and the Insurance type. Given an Agent name, display the policies that were sold by that agent. Similarly, print the policies in the given Insurance type. Write a program to do the same. They have a list of few policies and want to update the list with a few more policies.


Create a class named Agent with the following attributes

Data Type Variable Name
int _id
string _name


Include appropriate Properties as follows.
private string _name;
public string Name
{
    get { return _name; }
    set { _name = value; }
}
Include a 2 argument constructor with _id and _name as arguments.

Create a class named InsuranceType with the following attributes

Data Type Variable Name
int _id
string _type


Include appropriate properties.
Include a 2 argument constructor with _id and _type as arguments.

Create a class named Policy with the following attributes

Data Type Variable Name
int _id
InsuranceType _insuranceType
Agent _agent
double _premiumPayable


Include appropriate Properties.
Include a 4 argument constructor with _id ,_insuranceType,_agent,_premiumPayable as arguments.

Create a class named PolicyBO and include the following method,

Method Name Method Description
ListPoliciesByAgent(List<Policy> policyList, String name) The return type of this method is List<Policy>. This method returns a list of policies for given agent
ListPoliciesByType(List<Policy> policyList, String type) The return type of this method is List<Policy>. This method returns a list of policies under given insurance type



Create a class named Program to test the above classes.
The collection for Policy class is prepopulated with predefined values, and get n details from the user and add it to the predefined list.
Get the policy details as a single string separated by " , " in the order policy id, insuranceType id, insurance type, agent id, agent name, premium payable. Split the input using Split() method, and store the policy details in a list of type Policy.

Create a delegate method named AgentPolicyList(List<Policy> policyList,string _agentName) with List<Policy> as return type, and call the ListPoliciesByAgent method using this delegete method,to get the list of policies for given agent.
Use String.Format("{0, -20}{1, -20}{2:#.00}", "PolicyId","InsuranceType","PremiumPayable"), to display the policies for agent.

Create another delegate method named TypePolicyList(List<Policy> policyList, string _insuranceType) with List<Policy> as return type, and call the ListPoliciesByType method using this delegete method,to get the list of policies for given insurance type.
String.Format("{0, -20}{1, -20}{2:#.00}", PolicyId,InsuranceType,PremiumPayable), to display the policies for insurance type.


Input and Output Format :
First line of the input corresponds to the number of policy details, n.
Next n lines of the input corresponds to the Policy details separated by " , ".
(n+1)th line of the input corresponds to the name of the agent name, to get the policy details.
Last input corresponds to the insurance type, to get the policy details.
All text in bold corresponds to input and rest corresponds to output.

The following logs are already present in the Policy list. These values have to be prefilled before adding new policy details.

PolicyId InsuranceTypeId InsuranceType Agent Id User PremiumPayable
2154 3158 Life Insurance 154 Jacob 25000
3401 3548 Health Insurance 251 Daniel 30000
2549 3154 Vehicle Insurance 154 Jacob 15000
3504 3158 Life Insurance 251 Daniel 20000
2501 3548 Health Insurance 624 Andrew 35000
2509 3154 Vehicle Insurance 624 Andrew 27000


Sample Input and Output :
2
2541,3254,Life Insurance,251,Aiden,20000.50
2571,3846,Health Insurance,154,Joseph,15000
Daniel

Policy List
PolicyId          InsuranceType         PremiumPayable
3401                Health Insurance    30000.00
3504                Life Insurance           20000.00
Life Insurance
Policy List
PolicyId            Agent               PremiumPayable
2154                 Jacob                25000.00
3504                 Daniel                20000.00
2541                 Aiden                 20000.50

--------------------------

Thanks

Solutions

Expert Solution

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

delegate List<Policy> Searching(List<Policy> list,string search);

    //........Agent class...............
    public class Agent
    {
        public int _id;
        public string _name;
     
        public Agent(int id,string name)
            {
                _id=id;
                _name=name;
            }
     

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
     
        public int ID
        {
            get { return _id; }
            set { _id = value; }
        }
    }

    //........Insurance Type class...............
    public class InsuranceType
    {
        public int _id;
        public string _type;
     
        public InsuranceType(int id,string type)
            {
                _id=id;
                _type=type;
            }
     
            public string Type
            {
                get { return _type; }
                set { _type = value; }
            }
     
            public int ID
            {
                get { return _id; }
                set { _id = value; }
            }
    }

    public class Policy
    {
        public int _id;
        public double _premiumPayable;
        public InsuranceType _insuranceType;
        public Agent _agent;
     
        public Policy(int id,InsuranceType insuranceType,Agent agent,double premiumPayable)
            {
                _id=id;
                _insuranceType=insuranceType;
                _agent=agent;
                _premiumPayable=premiumPayable;
            }
     

            public double PremiumPayable
            {
                get { return _premiumPayable; }
                set { _premiumPayable = value; }
            }
     
            public int ID
            {
                get { return _id; }
                set { _id = value; }
            }
    }

    //..................PolicyBO Class......................

    public class PolicyBO
    {
     
        public List<Policy> ListPoliciesByAgent(List<Policy> policyList, String name)
        {
            List<Policy> new1=new List<Policy>();
            //Policy p=new Policy();
            foreach(Policy p in policyList)
            {
                if(p._agent.Name==name)
                {
                    new1.Add(p);
                }
            }
            return new1;
        }
         
        public List<Policy> ListPoliciesByType(List<Policy> policyList, String type)
        {
            List<Policy> new1=new List<Policy>();
            foreach(Policy p in policyList)
            {
                if(p._insuranceType.Type==type)
                {
                    new1.Add(p);
                }
            }
            return new1;
        }
    }

    public class Program
    {
        public static void Main(string[] args)
        {
            List<Policy> policyList=new List<Policy>();
            Agent a;
            InsuranceType i_t;
            Policy p;
            string str;
            double pp=25000;
            int id;
           
            a=new Agent(154,"jacob");
            i_t=new InsuranceType(3158,"life insurance");
            p=new Policy(2154,i_t,a,25000);
            policyList.Add(p);
           
            a=new Agent(251,"daniel");
            i_t=new InsuranceType(3548,"health insurance");
            p=new Policy(3401,i_t,a,30000);
            policyList.Add(p);
           
            a=new Agent(154,"jacob");
            i_t=new InsuranceType(3154,"vehicle insurance");
            p=new Policy(2549,i_t,a,15000);
            policyList.Add(p);
           
            a=new Agent(251,"daniel");
            i_t=new InsuranceType(3158,"life insurance");
            p=new Policy(3504,i_t,a,20000);
            policyList.Add(p);
           
            a=new Agent(624,"andrew");
            i_t=new InsuranceType(3548,"health insyrance");
            p=new Policy(2501,i_t,a,35000);
            policyList.Add(p);
           
            a=new Agent(624,"andrew");
            i_t=new InsuranceType(3154,"vehicle insurance");
            p=new Policy(2509,i_t,a,27000);
            policyList.Add(p);
           
            /*.......................
            .....using delegates.....
            .......................*/
            PolicyBO pb=new PolicyBO();
            List<Policy> found=new List<Policy>();
            string search;
           
           
           
            //Searching policies by agent name
            Searching sc=new Searching(pb.ListPoliciesByAgent);
            Console.Write("Enter a name:");
            search=Console.ReadLine();
            found=sc(policyList,search);
            Console.WriteLine("ID\tInsuranceType\tPremiumBayable\n");
            foreach(Policy res in found)
            {
                Console.WriteLine(res.ID+"\t"+res._insuranceType.Type+"\t"+res.PremiumPayable+"\n");
            }
           
            //Searching policies by Insurance Type
            sc=new Searching(pb.ListPoliciesByType);
            Console.Write("Enter Insurance Type:");
            search=Console.ReadLine();
            found=sc(policyList,search);
            Console.WriteLine("ID\tInsuranceType\tPremiumBayable\n");
            foreach(Policy res in found)
            {
                Console.WriteLine(res.ID+"\t"+res._insuranceType.Type+"\t"+res.PremiumPayable+"\n");
            }
            Console.WriteLine("\nEnd\n");
        }
    }


Related Solutions

can someone code this problem please? Introduction Students will create a C++ program that simulates a...
can someone code this problem please? Introduction Students will create a C++ program that simulates a Pokemon battle mainly with the usage of a while loop, classes, structs, functions, pass by reference and arrays. Students will be expected to create the player’s pokemon and enemy pokemon using object-oriented programming (OOP). Scenario You’ve been assigned the role of creating a Pokemon fight simulator between a player’s Pikachu and the enemy CPU’s Mewtwo. You need to create a simple Pokemon battle simulation...
provide a C code (only C please) that gives the output below: ************************************ *         Menu HW...
provide a C code (only C please) that gives the output below: ************************************ *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1. Creating polynomials * * 2. Adding polynomials * * 3. Multiplying polynomials. * * 4. Displaying polynomials * * 5. Clearing polynomials. * * 6. Quit. * *********************************** Select the option (1 through 6): 7 You should not be in this class! ************************************* *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1. Creating polynomials...
Can someone please provide a feedback on the discussion post below. Thank you. It is a...
Can someone please provide a feedback on the discussion post below. Thank you. It is a marketing management class. Amazon.com is one of the fastest growing companies to date. Amazon utilizes Facebook, Twitter, YouTube, and a company blog in order to reach out to their consumers. What I have noticed on their YouTube channel is that they have a variety of different kinds of videos that all relate to the average consumer. In addition, Amazon is able to use celebrity...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class Phase1 { /* Translates the MAL instruction to 1-3 TAL instructions * and returns the TAL instructions in a list * * mals: input program as a list of Instruction objects * * returns a list of TAL instructions (should be same size or longer than input list) */ public static List<Instruction> temp = new LinkedList<>(); public static List<Instruction> mal_to_tal(List<Instruction> mals) { for (int...
A principal-agent problem can arise when an insurance agent sells a policy to a buyer who...
A principal-agent problem can arise when an insurance agent sells a policy to a buyer who uses it as an incentive to behave badly. a principal hires an agent to do something on their behalf, but the principal cannot perfectly observe the agent's actions. an agent hires a principal to do something on their behalf, and the agent can observe the principal's actions. a principal uses an agent to accomplish a task the principal wants credit for completing. Which of...
can someone translate this pseudo code to actual c++ code while (not the end of the...
can someone translate this pseudo code to actual c++ code while (not the end of the input) If the next input is a number read it and push it on the stack else If the next input is an operator, read it pop 2 operands off of the stack apply the operator push the result onto the stack When you reach the end of the input: if there is one number on the stack, print it else error
can someone please check the code below? Thank you Hunterville College Tuition Design a program for...
can someone please check the code below? Thank you Hunterville College Tuition Design a program for Hunterville College. The current tuition is $20,000 per year. Allow the user to enter the rate the tuition increases each year. Display the tuition each year for the next 10 years. For the programming problem, create the pseudocode and enter it below. Enter pseudocode here start     Declarations             num tuition             num year                         num TOTAL_YEARS = 10             num INCREASE_RATE...
can someone please check the code below? Thank you Hunterville College Tuition Design a program for...
can someone please check the code below? Thank you Hunterville College Tuition Design a program for Hunterville College. The current tuition is $20,000 per year. Allow the user to enter the rate the tuition increases each year. Display the tuition each year for the next 10 years. For the programming problem, create the pseudocode and enter it below. Enter pseudocode here start     Declarations             num tuition             num year                         num TOTAL_YEARS = 10             num INCREASE_RATE...
C++ Problem. I am providing the code. Just Please provide the new function and highlight it....
C++ Problem. I am providing the code. Just Please provide the new function and highlight it. implement the functions replaceAt, seqSearch, and remove. Test your new function too in main. Also, Test Old functions in main. Show the output. Also, modify the functions accordingly which have "See Programming Exercise 22". main.cpp : #include <iostream> using namespace std; #include "arrayListTypetempl.h" int main(){    arrayListType<int> intList;    arrayListType<char> charList;       intList.insertEnd(5);    intList.insertEnd(3);    intList.insertEnd(4);    intList.insertEnd(55);       charList.insertEnd('a');   ...
Can someone please explain to me the steps in journalizing events in accounting and then turning...
Can someone please explain to me the steps in journalizing events in accounting and then turning them into income statements. Like which assets and liabilities are credits and which are debits?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT