0% found this document useful (0 votes)
48 views7 pages

Java Vehicle Insurance System Code

Uploaded by

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

Java Vehicle Insurance System Code

Uploaded by

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

import [Link].

ArrayList;
import [Link];
import [Link];

public class StarProtectVehicleApp {


static Scanner scanner = new Scanner([Link]);
static ArrayList<Underwriter> underwriters = new ArrayList<>();
static int underwriterIdCounter = 1; // For auto-incrementing Underwriter ID
static int policyIdCounter = 1; // For auto-incrementing Policy ID
static Admin admin = new Admin("admin", "admin@123");

public static void main(String[] args) {


while (true) {
[Link]("Welcome to Star Protect Vehicle System");
[Link]("1. Admin Login");
[Link]("2. Underwriter Login");
[Link]("Choose your role (1/2): ");
int roleChoice = [Link]();
[Link](); // Consume newline

switch (roleChoice) {
case 1:
adminLogin();
break;
case 2:
underwriterLogin();
break;
default:
[Link]("Invalid choice. Please try again.");
}
}
}

private static void adminLogin() {


[Link]("Enter Admin User ID: ");
String userId = [Link]();
[Link]("Enter Admin Password: ");
String password = [Link]();

if ([Link](userId, password)) {
adminMenu();
} else {
[Link]("Invalid credentials. Please try again.");
}
}

private static void adminMenu() {


boolean exit = false;
while (!exit) {
[Link]("\nAdmin Menu:");
[Link]("1. Register Underwriter");
[Link]("2. Search Underwriter");
[Link]("3. Update Underwriter Password");
[Link]("4. Delete Underwriter");
[Link]("5. View All Underwriters");
[Link]("6. View Vehicles by Underwriter ID");
[Link]("7. Exit");
[Link]("Enter your choice: ");
int adminChoice = [Link]();
[Link](); // Consume newline

switch (adminChoice) {
case 1:
[Link]();
break;
case 2:
[Link]();
break;
case 3:
[Link]();
break;
case 4:
[Link]();
break;
case 5:
[Link]();
break;
case 6:
[Link]();
break;
case 7:
exit = true;
break;
default:
[Link]("Invalid choice. Please try again.");
}
}
}

private static void underwriterLogin() {


[Link]("Enter Underwriter ID: ");
int underwriterId = [Link]();
[Link](); // Consume newline
[Link]("Enter Underwriter Password: ");
String password = [Link]();

for (Underwriter underwriter : underwriters) {


if ([Link] == underwriterId &&
[Link](password)) {
underwriterMenu(underwriter);
return;
}
}
[Link]("Invalid Underwriter ID or password.");
}

private static void underwriterMenu(Underwriter underwriter) {


boolean exit = false;
while (!exit) {
[Link]("\nUnderwriter Menu:");
[Link]("1. Create a new Vehicle Insurance");
[Link]("2. Renew a Policy");
[Link]("3. Change Policy Type");
[Link]("4. View Policies");
[Link]("5. Exit");
[Link]("Enter your choice: ");
int underwriterChoice = [Link]();
[Link](); // Consume newline
switch (underwriterChoice) {
case 1:
[Link]();
break;
case 2:
[Link]();
break;
case 3:
[Link]();
break;
case 4:
[Link]();
break;
case 5:
exit = true;
break;
default:
[Link]("Invalid choice. Please try again.");
}
}
}
}

class Admin {
private String adminUserId;
private String adminPassword;

public Admin(String adminUserId, String adminPassword) {


[Link] = adminUserId;
[Link] = adminPassword;
}

public boolean validateAdmin(String userId, String password) {


return [Link](userId) && [Link](password);
}

public void registerUnderwriter() {


[Link]("Enter Underwriter Name: ");
String name = [Link]();
[Link]("Enter Date of Birth (dd/MM/yyyy): ");
String dob = [Link]();
[Link]("Enter Joining Date (dd/MM/yyyy): ");
String joiningDate = [Link]();

// Ask for password


[Link]("Enter Underwriter Password: ");
String password = [Link]();

Underwriter underwriter = new


Underwriter([Link]++, name, dob, joiningDate,
password);
[Link](underwriter);
[Link]("Underwriter Registered Successfully. Generated ID: " +
[Link]);
}

public void searchUnderwriter() {


[Link]("Enter Underwriter ID to search: ");
int id = [Link]();
[Link](); // consume newline
for (Underwriter underwriter : [Link]) {
if ([Link] == id) {
[Link](underwriter);
return;
}
}
[Link]("Underwriter not found.");
}

public void updateUnderwriterPassword() {


[Link]("Enter Underwriter ID: ");
int id = [Link]();
[Link](); // consume newline
for (Underwriter underwriter : [Link]) {
if ([Link] == id) {
[Link]("Enter new password: ");
[Link] = [Link]();
[Link]("Password updated successfully.");
return;
}
}
[Link]("Underwriter not found.");
}

public void deleteUnderwriter() {


[Link]("Enter Underwriter ID: ");
int id = [Link]();
[Link](); // consume newline
for (Underwriter underwriter : [Link]) {
if ([Link] == id) {
[Link](underwriter);
[Link]("Underwriter deleted successfully.");
return;
}
}
[Link]("Underwriter not found.");
}

public void viewAllUnderwriters() {


if ([Link]()) {
[Link]("No underwriters registered.");
} else {
for (Underwriter underwriter : [Link]) {
[Link](underwriter);
}
}
}

public void viewVehiclesByUnderwriterId() {


[Link]("Enter Underwriter ID: ");
int id = [Link]();
[Link](); // consume newline
for (Underwriter underwriter : [Link]) {
if ([Link] == id) {
[Link]();
return;
}
}
[Link]("Underwriter not found.");
}
}

class Underwriter {
int id;
String name;
String dob;
String joiningDate;
String password;
ArrayList<VehicleInsurance> vehicles = new ArrayList<>();

public Underwriter(int id, String name, String dob, String joiningDate, String
password) {
[Link] = id;
[Link] = name;
[Link] = dob;
[Link] = joiningDate;
[Link] = password;
}

public void createVehicleInsurance() {


[Link]("Enter Vehicle Number: ");
String vehicleNo = [Link]();
[Link]("Enter Vehicle Type (2-wheeler/4-wheeler): ");
String vehicleType = [Link]();
[Link]("Enter Customer Name: ");
String customerName = [Link]();
[Link]("Enter Engine Number: ");
int engineNo = [Link]();
[Link]("Enter Chassis Number: ");
int chassisNo = [Link]();
[Link]("Enter Phone Number: ");
long phoneNo = [Link]();
[Link](); // Consume newline
[Link]("Enter Insurance Type (Full/ThirdParty): ");
String insuranceType = [Link]();
double premiumAmt = calculatePremium(insuranceType);

Date fromDate = new Date(); // Current date


Date toDate = new Date([Link]() + (365L * 24 * 60 * 60 *
1000)); // 1 year later

VehicleInsurance insurance = new


VehicleInsurance([Link]++, vehicleNo,
vehicleType, customerName, engineNo, chassisNo, phoneNo,
insuranceType, premiumAmt, fromDate, toDate);
[Link](insurance);
[Link]("Vehicle Insurance created successfully. Policy ID: " +
[Link]);
}

private double calculatePremium(String insuranceType) {


switch (insuranceType) {
case "Full":
return 1000; // Example premium amount for full insurance
case "ThirdParty":
return 500; // Example premium amount for third-party insurance
default:
return 0;
}
}

public void renewPolicy() {


[Link]("Enter Policy ID to renew: ");
int policyId = [Link]();
for (VehicleInsurance insurance : vehicles) {
if ([Link] == policyId) {
[Link]();
[Link]("Policy renewed successfully.");
return;
}
}
[Link]("Policy not found.");
}

public void changePolicyType() {


[Link]("Enter Policy ID to change type: ");
int policyId = [Link]();
[Link](); // consume newline
for (VehicleInsurance insurance : vehicles) {
if ([Link] == policyId) {
[Link]("Enter new Insurance Type (Full/ThirdParty): ");
String newType = [Link]();
[Link] = newType;
[Link] = calculatePremium(newType); // Recalculate
premium
[Link]("Policy type changed successfully.");
return;
}
}
[Link]("Policy not found.");
}

public void viewPolicies() {


if ([Link]()) {
[Link]("No policies available for this underwriter.");
} else {
for (VehicleInsurance insurance : vehicles) {
[Link](insurance);
}
}
}

@Override
public String toString() {
return "Underwriter ID: " + id + ", Name: " + name + ", DOB: " + dob + ",
Joining Date: " + joiningDate;
}
}

class VehicleInsurance {
int policyId;
String vehicleNumber;
String vehicleType;
String customerName;
int engineNumber;
int chassisNumber;
long phoneNumber;
String insuranceType;
double premiumAmount;
Date fromDate;
Date toDate;

public VehicleInsurance(int policyId, String vehicleNumber, String vehicleType,


String customerName,
int engineNumber,
int chassisNumber, long phoneNumber, String insuranceType, double
premiumAmount, Date fromDate,
Date toDate) {
[Link] = policyId;
[Link] = vehicleNumber;
[Link] = vehicleType;
[Link] = customerName;
[Link] = engineNumber;
[Link] = chassisNumber;
[Link] = phoneNumber;
[Link] = insuranceType;
[Link] = premiumAmount;
[Link] = fromDate;
[Link] = toDate;
}

public void renew() {


[Link] = new Date();
[Link] = new Date([Link]() + (365L * 24 * 60 * 60 *
1000)); // Extend for 1 year
}

@Override
public String toString() {
return "Policy ID: " + policyId + ", Vehicle No: " + vehicleNumber + ",
Type: " + vehicleType +
", Customer: " + customerName + ", Premium: " + premiumAmount + ",
Validity: " + fromDate + " to "
+ toDate;
}
}

Common questions

Powered by AI

The system uses ArrayLists to manage collections of underwriters and insurance policies, allowing dynamic resizing and efficient iterating over stored elements. This facilitates quick querying and updating of data. Additionally, using unique IDs assists in fast retrieval and modification of specific records, enabling efficient management of insurances.

The system cross-verifies the entered Underwriter ID and Password against its records. If incorrect credentials are provided, it denies access without specifying details of which component (ID or password) was incorrect. This mechanism prevents unauthorized access while maintaining user confidentiality.

The premium calculation function determines the cost of an insurance policy based on the selected type (Full or ThirdParty). It assigns predetermined values (e.g., $1000 for Full, $500 for ThirdParty) which directly influence the policy's pricing structure, providing clear financial terms upfront to the customer.

Admin logins are verified by matching the entered User ID and Password against stored credentials. If validated, the Admin gains access to perform tasks such as registering Underwriters and managing policies. This verification ensures that only authorized users perform administrative tasks, thus maintaining system integrity and security.

When a policy type is changed, the system recalculates the premium using 'calculatePremium'. By switching the insurance type (e.g., from ThirdParty to Full), the premium amount is reassigned according to the predefined rates, ensuring premium accuracy aligned with new coverage terms. This automates adjustments, reflecting policy changes in real-time.

User interaction is managed via sequential prompts requesting details such as Vehicle Number, Customer Name, Engine Number, Chassis Number, and Phone Number. By receiving inputs sequentially, the system ensures that all necessary data is collected to process insurance creation effectively.

An Underwriter in the system is responsible for: 1) Creating new Vehicle Insurance policies, 2) Renewing existing policies, 3) Changing the type of an insurance policy, and 4) Viewing all policies managed by them.

Upon renewal, the 'fromDate' is updated to the current date, and the 'toDate' is extended by one year from the new 'fromDate'. This extends the policy’s validity while maintaining existing terms unless altered by underwriter action.

The system employs auto-incrementing counters for Underwriter IDs and Policy IDs. Each time a new Underwriter is registered, the 'underwriterIdCounter' is incremented, ensuring uniqueness. Similarly, the 'policyIdCounter' is incremented when a new policy is created, maintaining distinct IDs.

To register a new Underwriter, an Admin must: 1) Enter the Underwriter's Name, 2) Provide the Date of Birth in 'dd/MM/yyyy' format, 3) Input the Joining Date in the same format, and 4) Set a Password. Upon completion, an Underwriter ID is generated automatically.

You might also like