Question: So in my java code I got everything to look the way it should. for some reason cant put formated currency in like: comma and

So in my java code I got everything to look the way it should. for some reason cant put formated currency in like: comma and dollar sign for the salary. I also just read I need to put forEach method, and I don't import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
class Employee {
private String id;
private String lastName;
private String firstName;
private int salary;
public Employee(String id, String lastName, String firstName, int salary){
this.id = id;
this.lastName = lastName;
this.firstName = firstName;
this.salary = salary;
}
public String getId(){
return id;
}
public String getLastName(){
return lastName;
}
public String getFirstName(){
return firstName;
}
public int getSalary(){
return salary;
}
@Override
public String toString(){
return "ID "+ id +":"
+ lastName +","
+ firstName +
", salary $"+ salary;
}
}
//ArrayList
//employee variables
//not in order
//used same names and info from instructions
public class listEmployee {
public static void main(String[] args){
Employee[] employeesArray ={
new Employee("67765", "Jones", "Don", 140000),
new Employee("11111", "Scott", "Bob", 65000),
new Employee("56789", "Jones", "Dan", 130000),
new Employee("23232", "Baker", "Amy", 100000),
new Employee("24680", "Scott", "Ann", 90000),
new Employee("13579", "Jones", "Pat", 80000),
new Employee("45454", "Perez", "Ava", 105000),
new Employee("12345", "Baker", "Tom", 200000)
};
//Collections and List methods
List employeesList = new ArrayList<>();
Collections.addAll(employeesList, employeesArray);
Collections.sort(employeesList,(e1, e2)->{
int lastNameComparison = e1.getLastName().compareTo(e2.getLastName());
if (lastNameComparison ==0){
return e1.getFirstName().compareTo(e2.getFirstName());
}
return lastNameComparison;
});
//final output
//sorted output
//reverse output
//iterator forward and reverse order
System.out.println("Staff Alpha sorted by names
");
employeesList.forEach(System.out::println);
List employeesLinkedList = new LinkedList<>(employeesList);
Iterator iterator = employeesLinkedList.iterator();
while (iterator.hasNext()){
iterator.next();
}
System.out.println("
Staff sorted Reverse Alpha
");
ListIterator listIterator = employeesLinkedList.listIterator(employeesLinkedList.size());
while (listIterator.hasPrevious()){
System.out.println(listIterator.previous());
}
}
}

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!