Question: What you need to do ( Change on Main.java only; Whenever you need to implement a code, you will find a comment like this /

What you need to do (Change on Main.java only; Whenever you need to implement a code, you will find a comment like this //######### Take Action Below #########)
public class Employee implements Comparable{
private String firstName;
private String lastName;
private String title;
private String ID;
private String level;
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public String getTitle(){
return title;
}
public String getID(){
return ID;
}
public String getLevel(){
return level;
}
public Employee(String firstName, String lastName, String title, String iD, String level){
super();
this.firstName = firstName;
this.lastName = lastName;
this.title = title;
ID = iD;
this.level = level;
}
@Override
public String toString(){
return String.format("%-15s %-15s %-40s %5s %5s ", firstName ,lastName, title, level, ID);
}
@Override
public int compareTo(Employee o){
return this.ID.compareTo(o.ID);
}
}
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
public class Main {
public static void main(String[] args){
ArrayList sorted = loadEmployee("NameList.csv");
// created a shuffled version
ArrayList unsorted = new ArrayList(sorted);
Collections.shuffle(unsorted);
//######### Take Action Below #########
// Add codes to sort the ArrayList and try them out
//1. Create and use an anonymous class that sorts by first name high to low
//2. Create and use a lambda expression that sorts by last name low to high
//3. Create and use a lambda expression that sorts by title
//4. Create and use a lambda expression that sorts first by title then by Level
//5. Create and use a lambda expression that sorts first by last name then by first name
Collections.sort(unsorted);
//######### Take Action Below #########
// Use Lambda expression to print all elements of unsorted ArrayList
}
public static ArrayList loadEmployee(String filename){
BufferedReader br = null;
FileReader fr = null;
ArrayList employees = new ArrayList();
ArrayList lines = new ArrayList();
try {
fr = new FileReader(filename);
br = new BufferedReader(fr);
String line;
br = new BufferedReader(new FileReader(filename));
while ((line = br.readLine())!= null){
lines.add(line);
}
} catch (IOException e){
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
if (fr != null)
fr.close();
} catch (IOException ex){
}
int count =0;
for (int i =0; i < lines.size(); i++){
String field[]= lines.get(count++).split(",");
employees.add(new Employee(field[0], field[1], field[2], String.format("%010d", i), field[3]));
count = count % lines.size();
}
}
return employees;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!