0% found this document useful (0 votes)
7 views15 pages

Java Insurance Management System Code

The document outlines the structure and implementation of an Insurance Management System in Java, including classes for Policy, Payment, and User, along with exception handling for various error scenarios. It features a main module that provides a user interface for adding users, policies, and processing payments. The system is designed to manage insurance policies and their associated payments effectively.

Uploaded by

vijayroshan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views15 pages

Java Insurance Management System Code

The document outlines the structure and implementation of an Insurance Management System in Java, including classes for Policy, Payment, and User, along with exception handling for various error scenarios. It features a main module that provides a user interface for adding users, policies, and processing payments. The system is designed to manage insurance policies and their associated payments effectively.

Uploaded by

vijayroshan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Coding Challenge: Insurance Management System

– J220 [Link]

Directory structure:

1
Entity/[Link]:

package entity;

public class Policy {


private int policyId;
private String policyName;
private double premiumAmount;
private double coverageAmount;
private int policyHolderId;

public Policy() {}

public Policy(int policyId, String policyName, double premiumAmount, double


coverageAmount, int policyHolderId) {
[Link] = policyId;
[Link] = policyName;
[Link] = premiumAmount;
[Link] = coverageAmount;
[Link] = policyHolderId;
}

public int getPolicyId() {


return policyId;
}

public void setPolicyId(int policyId) {


[Link] = policyId;
}

public String getPolicyName() {


return policyName;
}

public void setPolicyName(String policyName) {


[Link] = policyName;
}

public double getPremiumAmount() {


return premiumAmount;
}

public void setPremiumAmount(double premiumAmount) {


[Link] = premiumAmount;
}

2
public double getCoverageAmount() {
return coverageAmount;
}

public void setCoverageAmount(double coverageAmount) {


[Link] = coverageAmount;
}

public int getPolicyHolderId() {


return policyHolderId;
}

public void setPolicyHolderId(int policyHolderId) {


[Link] = policyHolderId;
}

@Override
public String toString() {
return "Policy { " +
"policyId=" + policyId +
", policyName='" + policyName + '\'' +
", premiumAmount=" + premiumAmount +
", coverageAmount=" + coverageAmount +
", policyHolderId=" + policyHolderId +
" }";
}
}

Entity/[Link]
package entity;

public class Payment {


private int paymentId;
private int policyId;
private double paymentAmount;
private String paymentDate;
private String paymentMode;
private String paymentStatus;

public Payment() {}

3
public Payment(int paymentId, int policyId, double paymentAmount, String
paymentDate, String paymentMode, String paymentStatus) {
[Link] = paymentId;
[Link] = policyId;
[Link] = paymentAmount;
[Link] = paymentDate;
[Link] = paymentMode;
[Link] = paymentStatus;
}

public int getPaymentId() {


return paymentId;
}

public void setPaymentId(int paymentId) {


[Link] = paymentId;
}

public int getPolicyId() {


return policyId;
}

public void setPolicyId(int policyId) {


[Link] = policyId;
}

public double getPaymentAmount() {


return paymentAmount;
}

public void setPaymentAmount(double paymentAmount) {


[Link] = paymentAmount;
}

public String getPaymentDate() {


return paymentDate;

4
}

public void setPaymentDate(String paymentDate) {


[Link] = paymentDate;
}

public String getPaymentMode() {


return paymentMode;
}

public void setPaymentMode(String paymentMode) {


[Link] = paymentMode;
}

public String getPaymentStatus() {


return paymentStatus;
}

public void setPaymentStatus(String paymentStatus) {


[Link] = paymentStatus;
}

@Override
public String toString() {
return "Payment { " +
"paymentId=" + paymentId +
", policyId=" + policyId +
", paymentAmount=" + paymentAmount +
", paymentDate='" + paymentDate + '\'' +
", paymentMode='" + paymentMode + '\'' +
", paymentStatus='" + paymentStatus + '\'' +
" }";
}
}

5
Entity/[Link]
package entity;

public class User {


private int userId;
private String username;
private String password;
private String role;

public User() {}

public User(int userId, String username, String password, String role) {


[Link] = userId;
[Link] = username;
[Link] = password;
[Link] = role;
}

public int getUserId() {


return userId;
}

public void setUserId(int userId) {


[Link] = userId;
}

public String getUsername() {


return username;
}

public void setUsername(String username) {


[Link] = username;
}

public String getPassword() {


return password;
}

public void setPassword(String password) {


[Link] = password;
}

public String getRole() {


return role;
}

6
public void setRole(String role) {
[Link] = role;
}

@Override
public String toString() {
return "User { " +
"userId=" + userId +
", username='" + username + '\'' +
", role='" + role + '\'' +
" }";
}
}

EXCEPTION/[Link]
package exception;

public class PaymentFailedException extends Exception {


public PaymentFailedException(String message) {
super(message);
}
}

package exception;

public class PolicyNotFoundException extends Exception {


public PolicyNotFoundException(String message) {
super(message);
}
}
package exception;

public class UserNotFoundException extends Exception {


public UserNotFoundException(String message) {
super(message);
}
}

7
MAIN/MAIN_MODULES:
package main;

import dao.*;
import entity.*;
import exception.*;

import [Link];
import [Link];

public class MainModule {


public static void main(String[] args) {
UserService userService = new UserServiceImpl();
PolicyService policyService = new PolicyServiceImpl();
PaymentService paymentService = new PaymentServiceImpl();

Scanner scanner = new Scanner([Link]);


boolean running = true;

while (running){
[Link]("\n--- Insurance Management System ---");
[Link]("1. Add User");
[Link]("2. Display Users");
[Link]("3. Add Policy");
[Link]("4. Display Policies");
[Link]("5. Make Payment");
[Link]("6. Display Payments");
[Link]("7. Exit");
[Link]("Enter your choice: ");
int choice = [Link]();

switch (choice) {
case 1:
[Link]("Enter userId, username, password, role: ");
User user = new User([Link](), [Link](), [Link](),
[Link]());
[Link](user);
break;
case 2:
[Link]();
break;
case 3:
//[Link]("Enter policy details:");
try {

8
[Link]("Policy ID: ");
int policyId = [Link]();
[Link](); // Consume the newline

[Link]("Policy Name: ");


String policyName = [Link]();

[Link]("Premium Amount: ");


double premiumAmount = [Link]();

[Link]("Coverage Amount: ");


double coverageAmount = [Link]();

[Link]("Policy Holder ID: ");


int policyHolderId = [Link]();

// Create Policy object


Policy policy = new Policy(policyId, policyName, premiumAmount,
coverageAmount, policyHolderId);

// Add the policy


[Link](policy);

} catch (InputMismatchException e) {
[Link]("Invalid input. Please enter the data in the correct
format.");
[Link](); // Clear the buffer
}
break;

case 4:
[Link]().forEach([Link]::println);
break;
case 5:
[Link]("Enter paymentId, policyId, paymentAmount, paymentDate,
paymentMode, paymentStatus: ");
Payment payment = new Payment([Link](), [Link](),
[Link](), [Link](), [Link](), [Link]());
try {
[Link](payment);
[Link]("Payment made successfully.");
} catch (PaymentFailedException e) {
[Link]([Link]());
}
break;

9
case 6:
[Link]();
break;
case 7:
running = false;
break;
default:
[Link]("Invalid choice. Try again.");
}
}
[Link]();
[Link]("Exiting... Goodbye!");
}
}

Outputs:

10
11
12
13
14
15

You might also like