Question

WRITE A JAVA PROGRAM THAT READS DATA FROM A .CSV FILE !! PLEASE SEE INSTRUCTIONS BELOW...

WRITE A JAVA PROGRAM THAT READS DATA FROM A .CSV FILE !!

PLEASE SEE INSTRUCTIONS BELOW !!

BELOW IS THE DATA THAT NEEDS TO BE CONTAINED INTO THE CSV FILE !!

employeeId,dbId,privileged,service,inactive,groupmbr,userName,JobFunction,JobFunctionCode,JobFunctionStatus
200,512,TRUE,FALSE,FALSE,PayrollAccess,Bob Fields,Administrator,3000,Active
210,532,TRUE,FALSE,FALSE,AdminAccess,Ann Parson,Administrator,3001,Inactive
220,552,TRUE,FALSE,FALSE,AcctsPayableAccess,Ima Shields,Engineer,1002,Active
230,572,TRUE,FALSE,FALSE,PayrollAccess,Chris Stephens,Administrator,3002,Inactive
211,534,FALSE,FALSE,TRUE,PayrollAccess,Pat Anderson,Developer,2003,Active
212,536,FALSE,FALSE,TRUE,PayrollAccess,Shelley Peterson,Administrator,3003,Inactive
213,538,FALSE,FALSE,FALSE,PayrollAccess,Brian Murray,Engineer,1004,Inactive
214,540,FALSE,FALSE,FALSE,PayrollAccess,Phil Grate,Engineer,1005,Active
221,554,FALSE,FALSE,FALSE,AcctsPayableAccess,Victor Fuzz,Administrator,3004,Inactive
222,556,FALSE,FALSE,FALSE,AcctsPayableAccess,Alan Snow,Developer,2004,Active
223,558,FALSE,FALSE,FALSE,AcctsPayableAccess,Valerie Williams,Administrator,3005,Inactive
224,560,FALSE,FALSE,FALSE,AcctsPayableAccess,Bob Walters,Engineer,1006,Active
231,574,FALSE,FALSE,FALSE,AcctsReceivableAccess,Sue Flynn,Developer,2005,Inactive
233,578,FALSE,FALSE,FALSE,AcctsReceivableAccess,Sean Antonini,Engineer,1007,Active
234,580,FALSE,FALSE,FALSE,AcctsReceivableAccess,Tom Lennon,Administrator,3006,Inactive
300,712,TRUE,TRUE,FALSE,PayrollAccess,John Knight,Administrator,3007,Inactive

A PROGRAM THAT READS DATA FROM A CSV FILE AND SHOWS MULTIPLE ENTITLEMENTS.

FOR EXAMPLE:

Input : Multiple Entitlements in the provided csv file is given (Eg : PayrollAccess,AcctsPayableAccess etc..)

Output : List of the identity Names who has the combination of those multiple entitlements.
[Eg : Alan Snow, Bob Fields, Ann Parson].

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Record.java

public class Record {
private int empId, dbId;
private boolean privileged, service, inactive;
private String grpMember, userName, jobFunction;
private int jobFunctionCode;
private String jobFunctionStatus;
  
public Record()
{
this.empId = this.dbId = 0;
this.privileged = this.service = this.inactive = false;
this.grpMember = this.userName = this.jobFunction = "";
this.jobFunctionCode = 0;
this.jobFunctionStatus = "";
}
  
public Record(int empId, int dbId, boolean privileged, boolean service, boolean inactive, String grpMember,
String userName, String jobFunction, int jobFunctionCode, String jobFunctionStatus)
{
this.empId = empId;
this.dbId = dbId;
this.privileged = privileged;
this.service = service;
this.inactive = inactive;
this.grpMember = grpMember;
this.userName = userName;
this.jobFunction = jobFunction;
this.jobFunctionCode = jobFunctionCode;
this.jobFunctionStatus = jobFunctionStatus;
}

public int getEmpId() {
return empId;
}

public int getDbId() {
return dbId;
}

public boolean isPrivileged() {
return privileged;
}

public boolean isService() {
return service;
}

public boolean isInactive() {
return inactive;
}

public String getGrpMember() {
return grpMember;
}

public String getUserName() {
return userName;
}

public String getJobFunction() {
return jobFunction;
}

public int getJobFunctionCode() {
return jobFunctionCode;
}

public String getJobFunctionStatus() {
return jobFunctionStatus;
}
}

CSVReader.java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class CSVReader {
private ArrayList<Record> records;
  
public CSVReader()
{
this.records = new ArrayList<>();
}
  
public int readFile(String fileName)
{
Scanner fileReader;
int count = 0;
try
{
fileReader = new Scanner(new File(fileName));
while(fileReader.hasNextLine())
{
String line = fileReader.nextLine().trim();
String[] data = line.split(",");
int empId = Integer.parseInt(data[0].trim());
int dbId = Integer.parseInt(data[1].trim());
boolean privileged = Boolean.parseBoolean(data[2].trim());
boolean service = Boolean.parseBoolean(data[3].trim());
boolean inactive = Boolean.parseBoolean(data[4].trim());
String grpMember = data[5].trim();
String userName = data[6].trim();
String jobFunction = data[7].trim();
int jobFunctionCode = Integer.parseInt(data[8].trim());
String jobFunctionStatus = data[9].trim();
  
records.add(new Record(empId, dbId, privileged, service, inactive, grpMember, userName,
jobFunction, jobFunctionCode, jobFunctionStatus));
count++;
}
fileReader.close();
}catch(FileNotFoundException fnfe){
System.out.println(fileName + " couldn't be found!");
System.exit(0);
}
return count;
}
  
public ArrayList<String> listIdentityWithSameEntitlements(String combination)
{
ArrayList<String> names;
  
// check string has comma
if(!combination.contains(","))
{
System.out.println("Combination should have atleast 1 comma!");
System.exit(0);
}
  
names = new ArrayList<>();
String[] data = combination.split(",");
for(String comb : data)
{
for(Record rec : records)
{
if(rec.getGrpMember().compareTo(comb) == 0)
names.add(rec.getUserName());
}
}
return names;
}
}

MainClass.java (Main class)

import java.util.ArrayList;
import java.util.Scanner;

public class MainClass {
private static final String FILENAME = "input.csv";
  
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
CSVReader reader = new CSVReader();
int count = reader.readFile(FILENAME);
System.out.println(count + " records were read successfully!");
  
System.out.print("\nPlease enter more than 1 combination of entitlements (separated by commas): ");
String combination = sc.nextLine().trim();
ArrayList<String> names = reader.listIdentityWithSameEntitlements(combination);
if(names.isEmpty())
System.out.println("\nNo records found!");
else
{
System.out.println("\n" + names.size() + " matches found:");
for(int i = 0; i < names.size(); i++)
{
if(i == names.size() - 1)
System.out.println(names.get(i));
else
System.out.print(names.get(i) + ", ");
}
}
}
}

****************************************************************** SCREENSHOT *********************************************************

Add a comment
Know the answer?
Add Answer to:
WRITE A JAVA PROGRAM THAT READS DATA FROM A .CSV FILE !! PLEASE SEE INSTRUCTIONS BELOW...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT