C sharp class example
InsurancePolicy.cs
using System.Collections.Generic;
using System. Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo
{
class InsurancePolicy
{
private string strPolicyNumber;
private string strPolicyHolder;
private char cType;
private DateTime dtEffective_date;
private DateTime dtMaturity_date;
private float flPolicyAmount;
private string strInsurer;
public void SetupPolicy()
{
string eff_date;
string mat_date;
Console.Write(“Please Enter Policy Number: “);
strPolicyNumber = Console.ReadLine();
Console.Write(“Please Enter Policy Holder Name: “);
strPolicyHolder = Console.ReadLine();
Console.Write(“Please Enter Policy Effective Date: “);
eff_date = Console.ReadLine();
dtEffective_date = Convert.ToDateTime(eff_date);
Console.Write(“Please Enter Policy Maturity Date: “);
mat_date = Console.ReadLine();
dtMaturity_date = Convert.ToDateTime(mat_date);
Console.Write(“Please Enter Policy Amount: “);
flPolicyAmount = Convert.ToSingle(Console.ReadLine());
Console.Write(“Please Enter Insurance Company Name: “);
strInsurer = Console.ReadLine();
Console.Write(“Please Enter Policy Type: A-Auto H-Home L-Life “);
cType = (char)Console.Read();
}
public void PolicyDetails()
{
Console.WriteLine();
Console.WriteLine(“\nPolicy Details”);
Console.WriteLine();
Console.WriteLine(“Policy Number: {0}”, strPolicyNumber);
Console.WriteLine(“Policyholder Name: {0}”, strPolicyHolder);
Console.WriteLine(“Policy Type: {0}”, cType);
Console.WriteLine(“Policy Effective Date ” +dtEffective_date);
Console.WriteLine(“Policy Maturity Date: ” + dtMaturity_date);
Console.WriteLine(“Policy Amount: {0}”, flPolicyAmount);
Console.WriteLine(“Insurance Company : {0}”, strInsurer);
}
}
}
Program.cs
using System.Collections.Generic;
using System. Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
InsurancePolicy MyPolicy = new InsurancePolicy();
MyPolicy.SetupPolicy();
MyPolicy.PolicyDetails();
Console.ReadKey();
}
}
}
Output
