Skip to content

Master #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CarInsuranceChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public boolean approved() {

public class CarInsuranceChecker {
public static void main(String[] args) {
Customer cu = new Customer();
Scanner sc = new Scanner(System.in);
System.out.println("=====================");
System.out.println("|| COVERAGE UNITED ||");
Expand All @@ -34,14 +35,23 @@ public static void main(String[] args) {
System.out.println("[3] Exit");
System.out.println("What do you want to do? ");
Questionnaire questionnaire = new Questionnaire();
PremiumCalculator premCalc = new PremiumCalculator();
InsuranceChecker fullCov = new InsuranceChecker();
InsuranceChecker partialCov = new PartialCoverage();
InsuranceChecker basicCov = new BasicCoverage();
int answer = sc.nextInt();
if (answer == 1) {
questionnaire.collectCustomerDetails();
printables pr = new printables(questionnaire);
pr.approved();
System.out.println("Customer's Premium is: " + premCalc.calculatePremium(15000, cu.getAccidentHistory(), cu.getDE()));
fullCov.checkInsurance(cu.getCarAge(), cu.getAccidentHistory());
partialCov.checkInsurance(cu.getCarAge(), cu.getAccidentHistory());
basicCov.checkInsurance(cu.getCarAge(), cu.getAccidentHistory());
} else if (answer == 2){
csvRelated cr = new csvRelated();
cr.insuranceList();
}
sc.close();
}
}
19 changes: 15 additions & 4 deletions InsuranceChecker.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
class InsuranceChecker {
void FullCoverage(int carAge, int accidentHistory){
boolean flag = false;
public boolean getFlag(){
return flag;
}
public void setCarModel(boolean flag){
this.flag = flag;
}
void checkInsurance(int carAge, int accidentHistory){
if(carAge <= 5 && accidentHistory == 0){
System.out.println("Full Coverage");
}
}
}

void PartialCoverage(int carAge, int accidentHistory){
if(carAge >= 6 && carAge <= 10 || accidentHistory <=1){
class PartialCoverage extends InsuranceChecker{
@Override void checkInsurance(int carAge, int accidentHistory){
if(carAge >= 6 && carAge <= 10 || accidentHistory >=1){
System.out.println("Partial Coverage");
}
}
}

void BasicCoverage(int carAge, int accidentHistory){
class BasicCoverage extends InsuranceChecker{
@Override void checkInsurance(int carAge, int accidentHistory){
if(carAge > 10){
System.out.println("Basic Coverage");
}
Expand Down
2 changes: 2 additions & 0 deletions approvedInsurance.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
"toby","20","4","something","4","4"
"jao","21","2","toyota","2","2"
"potato","24","6","tesla","5","69"
"ALF","19","3","TESLA","4","5"
"Freddy","44","3","Ford","2","1"
26 changes: 25 additions & 1 deletion csvRelated.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import java.util.Scanner;
import java.io.FileReader;
import com.opencsv.CSVReader;
import com.opencsv.CSVWriter;
Expand All @@ -9,15 +10,38 @@

class approvedList {
public void insuranceList(){
Scanner sc = new Scanner(System.in);
try (CSVReader csvReader = new CSVReader(new FileReader("approvedInsurance.csv"))) {
List<String[]> rows = csvReader.readAll(); // Read all rows at once
// Iterate and print each row
for (String[] row : rows) {
for (String value : row) {
System.out.print(String.format("%-30s", value));
}
System.out.println(); // Move to the next line
System.out.println();
}
System.out.println("[1] Search | [2] Delete | [3] Exit");
int choice = sc.nextInt();
if (choice == 1) {
try (CSVReader read = new CSVReader(new FileReader("approvedInsurance.csv"))) {
System.out.println("====================================================");
System.out.println("Enter Insurance ID");
System.out.println("====================================================");
sc.nextLine();
String searchID = sc.nextLine();
for (String[] array : rows) {
if (searchID.equalsIgnoreCase(array[0])) {
System.out.println("Match found: " + searchID);
System.out.println(String.join(",", array));
break;
} else {
System.out.println("No match: " + searchID);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (IOException | CsvException e) {
e.printStackTrace();
}
Expand Down
5 changes: 0 additions & 5 deletions src/CarInsuranceChecker.java

This file was deleted.

5 changes: 0 additions & 5 deletions src/Customer.java

This file was deleted.

19 changes: 0 additions & 19 deletions src/InsuranceChecker.java

This file was deleted.

5 changes: 0 additions & 5 deletions src/Person.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/PremiumCalculator.java

This file was deleted.