Advertisement
atlog007

Insurance.java

Jun 12th, 2025
710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.78 KB | Source Code | 0 0
  1. import java.util.*;
  2.  
  3. public class Insurance {
  4.  
  5.     static Scanner sc = new Scanner(System.in);
  6.     static List<String[]> policies = new ArrayList<>();
  7.  
  8.     public static void main(String[] args) {
  9.         int choice1 = -1;
  10.         int choice2 = -1;
  11.         while (choice1 != 0) {
  12.             System.out.println("[1] Policy Listing");
  13.             choice1 = sc.nextInt();
  14.             sc.nextLine();
  15.             switch (choice1) {
  16.                 case 1:
  17.                     choice2 = -1;
  18.                     while (choice2 != 0) {
  19.                         System.out.println("\n[1] Policy Listing\n[2] View Policy\n[0] Go back to Main menu\n");
  20.                         choice2 = sc.nextInt();
  21.                         sc.nextLine();
  22.                         switch (choice2) {
  23.                             case 1:
  24.                                 System.out.println("You have selected the policy listing feature.");
  25.                                 choice2 = inputPolicies();
  26.                                 break;
  27.                             case 2:
  28.                                 System.out.println("You have selected the view all policies feature.");
  29.                                 displayPolicies();
  30.                                 break;
  31.                             case 0:
  32.                                 System.out.println("Exiting.........");
  33.                                 choice2 = 0;
  34.                         }
  35.                     }
  36.             }
  37.         }
  38.  
  39. //        inputPolicies();
  40. //        displayPolicies();
  41.         sc.close();
  42.     }
  43.  
  44.     // Function to input all policies
  45.     public static int inputPolicies() {
  46.  
  47.         System.out.println("\n--- Insurance Policy Entry ---");
  48.  
  49.         String policyType = getPolicyType();
  50.         if (policyType == null) return 0;
  51.  
  52.         String policyTitle = getPolicyTitle();
  53.         if (policyTitle == null) return 0;
  54.  
  55.         System.out.print("Enter Sum Assured: ");
  56.         String sumAssured = sc.nextLine();
  57.  
  58.         System.out.print("Enter Premium: ");
  59.         String premium = sc.nextLine();
  60.  
  61.         System.out.print("Enter Term (in years): ");
  62.         String term = sc.nextLine();
  63.  
  64.         String[] policy = {policyType, policyTitle, sumAssured, premium, term};
  65.         policies.add(policy);
  66.  
  67.         return -1;
  68.     }
  69.  
  70.     // Function to get valid policy type
  71.     public static String getPolicyType() {
  72.         System.out.println("Select Policy Type:");
  73.         System.out.println("1. Generalinsurance");
  74.         System.out.println("2. Healthinsurance");
  75.         System.out.println("3. Motorinsurance");
  76.         System.out.print("Enter choice (1-3): ");
  77.         int typeChoice = sc.nextInt();
  78.         sc.nextLine(); // consume newline
  79.  
  80.         switch (typeChoice) {
  81.             case 1:
  82.                 return "Generalinsurance";
  83.             case 2:
  84.                 return "Healthinsurance";
  85.             case 3:
  86.                 return "Motorinsurance";
  87.             default:
  88.                 System.out.println("Invalid policy type choice.");
  89.                 return null;
  90.         }
  91.     }
  92.  
  93.     // Function to get valid policy title
  94.     public static String getPolicyTitle() {
  95.         System.out.println("Select Policy Title:");
  96.         System.out.println("1. BimaGold");
  97.         System.out.println("2. Janand");
  98.         System.out.println("3. Vridhdhi");
  99.         System.out.println("4. Child Career");
  100.         System.out.println("5. Floater");
  101.         System.out.println("6. Conventional");
  102.         System.out.print("Enter choice (1-6): ");
  103.         int titleChoice = sc.nextInt();
  104.         sc.nextLine(); // consume newline
  105.  
  106.         switch (titleChoice) {
  107.             case 1:
  108.                 return "BimaGold";
  109.             case 2:
  110.                 return "Janand";
  111.             case 3:
  112.                 return "Vridhdhi";
  113.             case 4:
  114.                 return "Child Career";
  115.             case 5:
  116.                 return "Floater";
  117.             case 6:
  118.                 return "Conventional";
  119.             default:
  120.                 System.out.println("Invalid policy title choice.");
  121.                 return null;
  122.         }
  123.     }
  124.  
  125.     // Function to display all entered policies
  126.     public static void displayPolicies() {
  127.         System.out.println("\n--- All Insurance Policies ---");
  128.         for (int i = 0; i < policies.size(); i++) {
  129.             String[] p = policies.get(i);
  130.             System.out.println("Policy " + (i + 1));
  131.             System.out.println("Policy Type : " + p[0]);
  132.             System.out.println("Policy Title: " + p[1]);
  133.             System.out.println("Sum Assured : " + p[2]);
  134.             System.out.println("Premium     : " + p[3]);
  135.             System.out.println("Term        : " + p[4] + " years");
  136.             System.out.println("---------------------------");
  137.         }
  138.     }
  139. }
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement