-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFetchRecordsFromCSV.java
More file actions
92 lines (67 loc) · 3.29 KB
/
FetchRecordsFromCSV.java
File metadata and controls
92 lines (67 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//************************************ DO NOT CHANGE ************************************
package com.employee;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class FetchRecordsFromCSV {
public static ArrayList<ExcelList> readFromCSV(String fileName) throws IOException{
String line = "";
ArrayList<ExcelList> allEmployees = new ArrayList<>();
BufferedReader br = new BufferedReader(new FileReader(fileName));
while((line = br.readLine())!=null) {
String[] employee = line.split(",");
ExcelList emp = new ExcelList();
emp.setEmpId(Integer.parseInt(employee[0]));
emp.setName(employee[1]);
emp.setAge(Integer.parseInt(employee[2]));
emp.setContact(employee[3]);
emp.setCompensation(Integer.parseInt(employee[4]));
emp.setRating(Integer.parseInt(employee[5]));
allEmployees.add(emp);
}
return allEmployees;
}
public String[] getBrowsingHistory() {
String str[] = {"facebook","Instagram","YouTube","Upgrad","Instagram"," StackOverFlow","facebook",
"facebook","google"," StackOverflow", "google", "Gmail", "upgrad", "espn","Youtube","Upgrad","Instagram"," StackOverFlow","facebook",
"facebook","google"," StackOverflow", "google", "gmail","w3School","Upgrad","gmail","facebook","Instagram","Youtube","Upgrad","Instagram"," StackOverFlow","facebook",
"Facebook","google"," StackOverflow", "Google", "Gmail", "upgrad", "Espn","Youtube","upgrad","Instagram"," Stackoverflow","facebook",
"facebook","google"," stackOverflow", "google", "gmail","w3School","Upgrad","gmail"};
return str;
}
public String[] getRestrictedWesites() {
String[] str = {"Instagram","Facebook","Espn","Youtube"};
return str;
}
//************************************ DO NOT CHANGE ************************************
// ************************************ TODO 1.3 ************************************
// Uncomment the method getPermanentEmployee
public PermanentEmployee[] getPermanentEmployee(String fileName) throws
IOException { ArrayList<ExcelList> empListPermanent = readFromCSV(fileName);
if(empListPermanent.size() == 0) { System.out.println("The data in the PermanentEmployeeRecords.csv is missing");
System.exit(0); } PermanentEmployee[] perm = new
PermanentEmployee[empListPermanent.size()]; int i = 0;
for (ExcelList e : empListPermanent) { perm[i] = new
PermanentEmployee(e.getEmpId(), e.getName(), e.getAge(), e.getContact(),
e.getCompensation(), e.getRating(), e.getExtraField()); i++; }
return perm;
}
// ************************************ TODO 1.4 ************************************
// Uncomment the method getContractEmployee
public ContractEmployee[] getContractEmployee(String fileName) throws IOException {
ArrayList<ExcelList> empListContract = readFromCSV(fileName);
if(empListContract.size() == 0) {
System.out.println("The data in the ContractEmployeeRecords.csv is missing");
System.exit(0);
}
ContractEmployee[] contract = new ContractEmployee[empListContract.size()];
int i = 0;
for (ExcelList e : empListContract) {
contract[i] = new ContractEmployee(e.getEmpId(), e.getName(), e.getAge(), e.getContact(),
e.getCompensation(), e.getRating(), e.getExtraField());
i++;
}
return contract;
}
}