Imagine you are designing a simple system for an insurance company to manage their insurance policies. Each insurance policy has the following attributes:
- Policy ID (a unique identifier)
- Policyholder Name
- Policy Start Date
- Policy End Date
- Premium Amount
Your task is to create a simple API or a command-line program in a programming language of your choice (e.g., Python, Java, C#) to manage these insurance policies. You need to implement the following functionalities:
- Add a New Policy: Allow the user to add a new insurance policy to the system. Prompt the user to enter the policyholder's name, start date, end date, and premium amount. Generate a unique policy ID for each policy.
- View Policy Details: Allow the user to view the details of a policy by entering the policy ID. Display all the attributes of the policy.
- List All Policies: Display a list of all policies, including their IDs and policyholder names.
- Calculate Total Premium: Calculate and display the total premium amount for all policies.
- Search for Policies: Allow the user to search for policies by policyholder name and display all matching policies.
Your program should provide a simple menu-driven interface that allows the user to perform these operations. You don't need to worry about saving data to a database or file for this exercise; you can store the policies in memory as a data structure.
Ensure that your code is well-structured, follows best practices, and handles edge cases (e.g., handling invalid user input gracefully). You can choose to use object-oriented programming or a different approach based on your preference.
If using API, expect below endpoints
This Go program uses the Gin web framework to create a RESTful API with the following endpoints:
- GET /policies/:id: Retrieve a policy by ID.
- POST /policies: Create a new policy.
- PUT /policies/:id: Update a policy by ID.
- DELETE /policies/:id: Delete a policy by ID.
- GET /policies: List all policies.
- GET /totalpremium: Calculate the total premium amount for all policies.