Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Insurance {
- static Scanner sc = new Scanner(System.in);
- static List<String[]> policies = new ArrayList<>();
- public static void main(String[] args) {
- int choice1 = -1;
- int choice2 = -1;
- while (choice1 != 0) {
- System.out.println("[1] Policy Listing");
- choice1 = sc.nextInt();
- sc.nextLine();
- switch (choice1) {
- case 1:
- choice2 = -1;
- while (choice2 != 0) {
- System.out.println("\n[1] Policy Listing\n[2] View Policy\n[0] Go back to Main menu\n");
- choice2 = sc.nextInt();
- sc.nextLine();
- switch (choice2) {
- case 1:
- System.out.println("You have selected the policy listing feature.");
- choice2 = inputPolicies();
- break;
- case 2:
- System.out.println("You have selected the view all policies feature.");
- displayPolicies();
- break;
- case 0:
- System.out.println("Exiting.........");
- choice2 = 0;
- }
- }
- }
- }
- // inputPolicies();
- // displayPolicies();
- sc.close();
- }
- // Function to input all policies
- public static int inputPolicies() {
- System.out.println("\n--- Insurance Policy Entry ---");
- String policyType = getPolicyType();
- if (policyType == null) return 0;
- String policyTitle = getPolicyTitle();
- if (policyTitle == null) return 0;
- System.out.print("Enter Sum Assured: ");
- String sumAssured = sc.nextLine();
- System.out.print("Enter Premium: ");
- String premium = sc.nextLine();
- System.out.print("Enter Term (in years): ");
- String term = sc.nextLine();
- String[] policy = {policyType, policyTitle, sumAssured, premium, term};
- policies.add(policy);
- return -1;
- }
- // Function to get valid policy type
- public static String getPolicyType() {
- System.out.println("Select Policy Type:");
- System.out.println("1. Generalinsurance");
- System.out.println("2. Healthinsurance");
- System.out.println("3. Motorinsurance");
- System.out.print("Enter choice (1-3): ");
- int typeChoice = sc.nextInt();
- sc.nextLine(); // consume newline
- switch (typeChoice) {
- case 1:
- return "Generalinsurance";
- case 2:
- return "Healthinsurance";
- case 3:
- return "Motorinsurance";
- default:
- System.out.println("Invalid policy type choice.");
- return null;
- }
- }
- // Function to get valid policy title
- public static String getPolicyTitle() {
- System.out.println("Select Policy Title:");
- System.out.println("1. BimaGold");
- System.out.println("2. Janand");
- System.out.println("3. Vridhdhi");
- System.out.println("4. Child Career");
- System.out.println("5. Floater");
- System.out.println("6. Conventional");
- System.out.print("Enter choice (1-6): ");
- int titleChoice = sc.nextInt();
- sc.nextLine(); // consume newline
- switch (titleChoice) {
- case 1:
- return "BimaGold";
- case 2:
- return "Janand";
- case 3:
- return "Vridhdhi";
- case 4:
- return "Child Career";
- case 5:
- return "Floater";
- case 6:
- return "Conventional";
- default:
- System.out.println("Invalid policy title choice.");
- return null;
- }
- }
- // Function to display all entered policies
- public static void displayPolicies() {
- System.out.println("\n--- All Insurance Policies ---");
- for (int i = 0; i < policies.size(); i++) {
- String[] p = policies.get(i);
- System.out.println("Policy " + (i + 1));
- System.out.println("Policy Type : " + p[0]);
- System.out.println("Policy Title: " + p[1]);
- System.out.println("Sum Assured : " + p[2]);
- System.out.println("Premium : " + p[3]);
- System.out.println("Term : " + p[4] + " years");
- System.out.println("---------------------------");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement