Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Devang
Insurance
0 Answer(s)      2 years and 7 months ago
Posted in : Java Beginners


package insu;

import java.util.ArrayList;

public class Customer {
    static int lastid=100;
    private String id;
    private String idproof;
    private String name;
    private int age;
    private String gender;
    private String address;


    Customer(){


    }

    public static int getLastid() {
        return lastid;
    }

    public static void setLastid(int lastid) {
        Customer.lastid = lastid;
    }

    public String getId() {
        return id;
    }

    public void genId() {
        ++Customer.lastid;
        id=""+Customer.getLastid();

    if(name.length()>2)
        id=name.substring(0, 3)+id;
    else{
        String tmp="";
        for(int i=0;i<3-name.length();i++)
            tmp=tmp+"0";
    id=name+tmp+id;
    }
    }

    public String getIdproof() {
        return idproof;
    }

    public void setIdproof(String idproof) {
        this.idproof = idproof;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

}

package insu;
import java.util.Date;

class CustomerPolicy {
    int cpolicyid;
    int policyid;
    Date startDate;
    Date endDate;
    static int lastid=8000;
    CustomerPolicy(){
        cpolicyid=++CustomerPolicy.lastid;
    }
    public Date getStartDate() {
        return startDate;
    }
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }
    public Date getEndDate() {
        return endDate;
    }
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
    public int getPolicyid() {
        return policyid;
    }
    public void setPolicyid(int policyid) {
        this.policyid = policyid;
    }
    public int getCpolicyid() {
        return cpolicyid;
    }
    public void setCpolicyid(int cpolicyid) {
        this.cpolicyid = cpolicyid;
    }


}

package insu;

import java.util.ArrayList;
import java.util.Scanner;

public class Insurance {
public static void main(String args[]){
    ArrayList<Customer> customers =new ArrayList<Customer>();
    ArrayList<Policy> policy =new ArrayList<Policy>();
    ArrayList<CustomerPolicy> cpolicy =new ArrayList<CustomerPolicy>();
    ArrayList<Tag> tags =new ArrayList<Tag>();
    Main sa=new Main();
    Scanner s=new Scanner(System.in);
    int ctr=0;
    do{
        System.out.println("Enter 1.Add a policy 2.Add a customer 3.Remove Customer 4.Tag a Policy 5.Display Tags  6.Search 7.Display Customers 8. Display Policy");
        ctr=s.nextInt();s.nextLine();
        switch(ctr){
        case 1:
            Policy p=sa.addPolicy();
            if(p==null)
                System.out.println("Invalid Input");
            else
            policy.add(p);
            break;
        case 2:
            if(policy.size()>0){
            Customer c=sa.addCustomer(cpolicy,tags,policy);
            if(c==null)
                System.out.println("Invalid Input");
            else
            customers.add(c);
            }
            else{
                System.out.println("Please add policies first");
            }
            break;
        case 3:
            System.out.println("Enter customer id");
            String cid=s.nextLine();boolean exist=false;
            for(int i=0;i<customers.size();i++){
                if(customers.get(i).getId().equals(cid)){
                    exist=true;
                    customers.remove(i);

                    for(int j=0;j<tags.size();j++)
                        if(tags.get(j).getCustomerid().equals(cid))
                            tags.remove(j);
                }

                if(!exist)
                    System.out.println("No such customer");
                else
                    System.out.println("Customer deleted successfully");
            }

            break;
        case 4:
            Tag t=sa.tagPolicy(cpolicy,policy);
            if(t!=null){
            tags.add(t);

            System.out.println("Tagged Successfully");
            }
            else
            {
            System.out.println("Invalid Input");    
            }
            break;
        case 5:
            for(Tag t1:tags){
                System.out.println("CustomerID:"+t1.getCustomerid()+"\t CustomerPolicyID:"+t1.getcPolicyid()+"\t PolicyID:"+sa.searchCustomerPolicy(t1.getcPolicyid(), cpolicy).getPolicyid());
            }
            break;
        case 6:
            sa.searchCustomer(customers);
            break;
        case 7:
            for(Customer t1:customers){
                System.out.println("CustomerID:"+t1.getId()+"\t Name:"+t1.getName());
            }
            break;
        case 8:
            System.out.println("===========Policy Details=========");
            for(Policy t1:policy){
                System.out.println(" Policy ID:"+t1.getId()+"\t Policy Name:"+t1.getName());
            }
            System.out.println("========Customer Policies==========");
            for(CustomerPolicy t1:cpolicy){
                System.out.println("Customer PolicyID:"+t1.getCpolicyid()+"  Policy ID:"+t1.getPolicyid()+"   StartDate:"+t1.getStartDate()+"  End Date:"+t1.getEndDate());
            }
            break;
        }
        System.out.println("Do you want to continue ,Enter y or n");
        if(s.nextLine().toLowerCase().equals("y"))
            ctr=999;
    }while(ctr==999);
}
}


package insu;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Scanner;

public class Main {
    Scanner s=new Scanner(System.in);

    public Customer addCustomer( ArrayList<CustomerPolicy> cpl,ArrayList<Tag> tag,ArrayList<Policy> pol){
        Customer c=new Customer();
        try{
            System.out.println("Enter your name");
            String name=s.nextLine();
            c.setName(name);
            System.out.println("Enter idproof number");
            String idproof=s.nextLine();
            c.setIdproof(idproof);
            System.out.println("Enter your age");
            int age=s.nextInt();s.nextLine();
            c.setAge(age);
            System.out.println("Enter your address");
            String address=s.nextLine();
            c.setAddress(address);
            System.out.println("Enter your gender");
            String gender=s.nextLine();
            c.setGender(gender);    
            c.genId();
            //Adding policy
            System.out.println("Enter policy id");
            int policyid=s.nextInt();s.nextLine();

            System.out.println("Enter start date dd-mm-yyyy");
            CustomerPolicy cp=new CustomerPolicy();

            String datep[]=s.nextLine().split("-");
            int dateparts[]=new int[3];
            for(int k=0;k<3;k++)
                dateparts[k]=Integer.parseInt(datep[k]);

            //Date parts will hold dateparts[0]=Day dateparts[1]=Month dateparts[2]=Year
            cp.setStartDate(new Date(dateparts[2]-1901,dateparts[1],dateparts[0]));
            cp.setPolicyid(policyid);
            //Search Policy
            Policy tmp=searchPolicy(policyid, pol);
            if(tmp!=null){
                Date tp=cp.getStartDate();
                int months=tp.getMonth()+tmp.getTenure();
                int years=months/12;
                tp.setMonth(months-1);
                tp.setYear(tp.getYear()+years);
                System.out.println("Tenure:"+tmp.getTenure());
                cp.setEndDate(tp);
                System.out.println(cp.getEndDate());
                cpl.add(cp);

                //Adding tag
                Tag tg=new Tag();
                tg.setCustomerid(c.getId());
                tg.setPolicyid(cp.getCpolicyid());
                tag.add(tg);
            }
            else
            {
                System.out.println("Invalid Policy");
            }
        }
        catch(Exception e){
            return null;
        }
        return c;
    }
    public Customer searchCustomer(ArrayList<Customer>al ){
        Customer c=null;
        int ctr=0;
        try{
            System.out.println("Enter 1.By Name 2.By Id 3.Sorted Customers");
            ctr=s.nextInt();s.nextLine();
            switch(ctr){
            case 1:
                System.out.println("Enter name");
                String name=s.nextLine();
                for(int i=0;i<al.size();i++)
                {
                    if(al.get(i).getName().equals(name))
                        c=al.get(i);

                }
                display(c);
                break;
            case 2:
                System.out.println("Enter id");
                String id=s.nextLine();
                for(int i=0;i<al.size();i++)
                {
                    if(al.get(i).getId().equals(id))
                        c=al.get(i);

                }
                display(c);
                break;
            case 3:
                Collections.sort(al,new Comparator<Customer>(){

                    public int compare(Customer c1, Customer c2) {

                        return c1.getName().compareTo(c2.getName());
                    }

                });
                for(int i=0;i<al.size();i++)
                    display(al.get(i));
                break;

            }
        }
        catch(Exception e){
            return null;
        }
        return c;
    }
    public void display(Customer c){
        System.out.println("::::::Customer Details:::::::");
        System.out.println("Id:"+c.getId());
        System.out.println("Name:"+c.getName());
        System.out.println("Age:"+c.getAge());
        System.out.println("Gender:"+c.getGender());
        System.out.println("Address:"+c.getAddress());


    }
    public Policy addPolicy(){
        Policy c=new Policy();
        try{
            System.out.println("Enter policy name");
            String name=s.nextLine();
            c.setName(name);
            System.out.println("Enter premium");
            float premium=s.nextFloat();s.nextLine();
            c.setPremium(premium);
            System.out.println("Enter tenure");
            int tenure=s.nextInt();s.nextLine();
            c.setTenure(tenure);


        }
        catch(Exception e){
            return null;
        }
        return c;
    }
    public Tag tagPolicy(ArrayList<CustomerPolicy> cpl,ArrayList<Policy> pol){
        Tag t=new Tag();
        try{
            System.out.println("Enter customerid");
            String cid=s.nextLine();
            System.out.println("Enter policyId");
            int pid=s.nextInt();s.nextLine();
            CustomerPolicy cp=new CustomerPolicy();
            cp.setPolicyid(pid);
            System.out.println("Enter Policy start date: dd-mm-yyyy");
            String datep[]=s.nextLine().split("-");
            int dateparts[]=new int[3];

            for(int k=0;k<3;k++)
                dateparts[k]=Integer.parseInt(datep[k]);

            //Date parts will hold dateparts[0]=Day dateparts[1]=Month dateparts[2]=Year
            cp.setStartDate(new Date(dateparts[2]-1901,dateparts[1],dateparts[0]));//Year count starts from 1901
            Policy pl=searchPolicy(pid, pol);
            if(pl!=null){
                Date tp=cp.getStartDate();
                int months=tp.getMonth()+pl.getTenure();
                int years=months/12;
                tp.setMonth(months-1);//Months are 0 indexed
                tp.setYear(tp.getYear()+years);

                cp.setEndDate(tp);
                System.out.println(cp.getEndDate());
                cpl.add(cp);

            t.setCustomerid(cid);
            t.setPolicyid(cp.getCpolicyid());
            }
        }
        catch(Exception e){return null;}
        return t;
    }
    public Policy searchPolicy(int id,ArrayList<Policy> pl){
        Policy p=null;
        for(Policy p1:pl)
            if(p1.getId()==id)
                p=p1;
        return p;
    }
    public CustomerPolicy searchCustomerPolicy(int id,ArrayList<CustomerPolicy> pl){

        CustomerPolicy p=null;
        for(CustomerPolicy p1:pl)
        {
            if(p1.getCpolicyid()==id)
                p=p1;
        }

        return p;
    }
}


package insu;

import java.util.Date;

public class Policy {
    private String name;
    private int id;
    static int lastid=1000;
    private int tenure;//inMonths
    Policy(){
        this.id=++lastid;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public float getPremium() {
        return premium;
    }
    public void setPremium(float premium) {
        this.premium = premium;
    }
    private float premium;
    public void setId(int id) {
        this.id = id;
    }
    public int getId() {
        return id;
    }
    public void setTenure(int tenure) {
        this.tenure = tenure;
    }
    public int getTenure() {
        return tenure;
    }

}

package insu;

class Tag{
String customerid;
int cpolicyid;
public String getCustomerid() {
    return customerid;
}
public void setCustomerid(String customerid) {
    this.customerid = customerid;
}
public int getcPolicyid() {
    return cpolicyid;
}
public void setPolicyid(int policyid) {
    this.cpolicyid = policyid;
}

}

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Insurance
java.util.ArrayList; import java.util.Scanner; public class Insurance { public static
how to do abstraction for insurance policy being issued...
how to do abstraction for insurance policy being issued...  an insurance policy is being insured.... now what will be the classes for policy and how to do abstraction of the same
Advertisements
Business Intelligence in Insurance
Business Intelligence in Insurance   ... to survive in the competitive market place. This is also true in insurance business... information is pre-requisite. This makes insurance companies using Business Intelligence
Writing ORM for Insurance table
Writing ORM for Insurance table   ... of our java file (Insurance.java), which we will map to the insurance table...;insurance_name" /> </property> <property name="
Preparing table for HQL Examples
;    In this lesson we will create insurance table and populate it with the data. We will use insurance table for rest of the HQL tutorial. To create the insurance table and insert the sample data, run the following sql
Hibernate Select Clause
from Insurance table using Hibernate Select Clause. The select clause picks up..., insurance.investementDate from Insurance insurance which selects all the rows..., insurance.investementDate) from Insurance table. Hibernate generates
Our Solutions, Rose India Software solutions, Software Solutions
& Insurance (BFSI), Manufacturing, Contracting, and Retail &... Insurance
Criteria Query Examples
all the records from Insurance table. In this lesson we will learn how...; Insurance insurance =  (Insurance) it.next();   
What is CICS?
, colleges and universities, airline reservation systems, insurance companies
Business Website Templates
, insurance agencies, accounting, publishing houses. You can easily customize those
hibernate code problem - Hibernate
hibernate code problem  String SQL_QUERY =" from Insurance as insurance where insurance. lngInsuranceId='1'"; Query query...();){ Insurance insurance=(Insurance)it .next(); System.out.println("ID
HQL from clause Example
clause is: from Insurance insurance Here is the full code of the from clause...;insurance";   Query query = session.createQuery...();){ Insurance insurance=(Insurance)it.next();  System.out.println("ID: 
HQL Order By Example
By Clause. In our example we will retrieve the data sorted on the insurance type...;insurance = (Insurance) it.next();   System.out.println("ID: " + insurance. getLngInsuranceId());   
Hibernate Criteria Expression (gt)
: insurance ID insurance_name invested_amount investement_date 2 Life Insurance... Life Insurance  500 2005-10-15 00:00:00
HQL Group By Clause Example
will calculate the sum of invested amount in each insurance type. Here is the java code for calculating the invested amount insurance wise:      ..._, insurance0_.insurance_name as col_1_0_ from insurance insurance0_ group
Hibernate Criteria Expression (ge)
). Table Name: insurance ID insurance_name... Insurance 25000 0000-00-00 00:00:00 1... 3 Life Insurance  500 2005-10-15 00:00:00
pq
java program to Define Interface Insurance with methods  java program to Define Interface Insurance with methods: details()(name, types of services), no. of branches(), No. of customers(), annual_income(). Implement these methods
Hibernate Criteria Expression (le)
;,Object val). Table Name: insurance ID insurance... Life Insurance 25000 0000-00-00 00:00:00... 3 Life Insurance  500 2005-10-15
Hibernate Criteria Expression (lt)
). Table Name: insurance ID insurance_name... Life Insurance 25000 0000-00-00 00:00:00 1... 3 Life Insurance  500 2005-10-15 00:00:00
HQL Where Clause Example
, the properties can be referred by name. For example: from Insurance where...;Language  String SQL_QUERY =" from Insurance  as insurance where insurance. lngInsuranceId='1'";  
java assignment
insurance options in JCheckBoxes. Use a ButtonGroup to allow the user to select only one of two insurance types√Ę‚?¨‚??HMO (health maintenance organization... for dental insurance and vision insurance options; the user can select one option, both
Program
Program  Define Interface Insurance with methods: details()(name, types of services), no. of branches(), No. of customers(), annual_income(). Implement these methods in its Implementation class LIC, National, BajajAlliance
Hibernate Criteria Expression (and)
;IngInsuranceId", new Long(6))). Table Name: insurance ID insurance_name invested_amount investement_date 2 Life Insurance 25000 0000-00-00 00:00:00
Hibernate Criteria Expression (or)
;, new Long(6))). Table Name: insurance ID insurance... Life Insurance 25000 0000-00-00 00:00:00... 3 Life Insurance  500 2005-10-15
Hibernate Avg() Function (Aggregate Functions)
: insurance ID insurance_name invested_amount investement_date 2 Life Insurance 25000 0000-00-00 00:00... 3 Life Insurance   500 2005-10-15 00:00:00
Hibernate Max() Function (Aggregate Functions)
: insurance ID insurance_name invested_amount investement_date 2 Life Insurance 25000 0000-00-00 00:00:00... 3 Life Insurance  500 2005-10-15 00:00:00
Hibernate Min() Function (Aggregate Functions)
aggregates the minimum value of the given column.  Table Name: insurance ID insurance_name invested_amount investement_date 2 Life Insurance 25000 0000-00-00 00:00:00 1 Givan Dhara
Hibernate Criteria Expression (eq)
parameters e.g.  eq("property_name",Object val). Table Name: insurance ID insurance_name invested_amount investement_date 2 Life Insurance 25000
hibernate - Hibernate
(); //Using from Clause String SQL_QUERY ="from Insurance insurance... it=query.iterate();it.hasNext();){ Insurance insurance=(Insurance)it.next...://www.roseindia.net * Java Class to map to the database insurance table */ public
delete row using id
= "delete from Insurance insurance where id = 2"; Query query = sess.createQuery...: delete [delete from pkg2.Insurance insurance where id = 2
Advertisements
 

 

 

DMCA.com