Java Whats Wrong With my Code Line 20 ArrayList  ? MAP Class package chapter21; import java.util.ArrayList; import java.util.TreeMap;   public class Map { Employee employees1[] = {   new Employee("12345", "Tom", "Baker", 200000), new Employee("56789", "Dan", "Jones", 130000), new Employee("24680", "Ann", "Scoot", 90000), new Employee("13579", "Pat", "Jones", 200000), new Employee("11111", "Bob", "Scott", 65000), new Employee("23232", "Scott", "Baker", 65000), new Employee("45454", "Amy", "Perez", 105000), new Employee("67676", "Jones", "BakwJoneser", 140000)   };   // create an array list object that will hold data type = Employee ArrayList employeeList = new ArrayList <>(); // iterate the array and add the employee to the list for (Employee employee1 : employees) { //add employee1 to the employeeList employeeList.add(employee1); }   System.out.println("All Employee\n"); // use and enhanced for loop to print the employees for (Employee employees : employeeList) { System.out.println(employee1); }   // create a tree map with String and Empolyee Objects TreeMap employeeTreeMap = new TreeMap<>(); for(Employee employee:employeeList){ //use for lope to add the employees to the TreeSet using put() method to get the employees IDs and Name employeeTreeMap.put(employee1.getId(),employee1); } // print each employee sorted by employee id System.out.println("Employees By ID #\n"); //iterate the tree map for(String id: employeeTreeMap.keySet()){ //Print out employee names and ID with Tree Map System.out.println(employeeTreeMap.get(id)); }   } } Employee Class  package chapter21; import java.text.DecimalFormat; import java.text.NumberFormat;   public class Employee { //Attributes (all private): private String id; private String lastName; private String firstName; private int salary;   // Methods  Employee (String id, String lastName, String firstName, int salary) { this.id = id; //pts to the data that is put into the constructor      this.lastName = lastName;     this.firstName = firstName;     this.salary = salary; } //Getters for all attributes    public String getId() { //creates a method to return the data         return id;     }    public String getLastName() {        return lastName;    }    public String getFirstName() {        return firstName;    }    public int getSalary() {        return salary;    }   // toString method to display an Employee's attributes (See output of executable below)    //Define the method to return the employee details.    @Override    public String toString() {               //Use number format and decimal format        //to format the salary to desired output.    //"ID 23232:Baker, Amy, salary $100,000"    // "ID 12345:Jones, Dan, salary $200,000"    //Number froamt returns a currency format         NumberFormat nfm = NumberFormat.getCurrencyInstance();        //        String pt = ((DecimalFormat) nfm).toPattern();        //        String npt = pt.replace("\u00A4", "").trim();        //create varaible to hold decimal         NumberFormat nfm2 = new DecimalFormat(npt);        //set to setMinimum to round up or down for miney format         nfm2.setMinimumFractionDigits(0);               //return //"ID + 23232 + : + Baker,+ " , " + Amy +, salary $+ 100,000"        return "ID " + id + ":" + lastName + ", " + firstName                            + ", salary $" + nfm2.format(salary);    } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java

Whats Wrong With my Code Line 20 ArrayList  ?

MAP Class

package chapter21;

import java.util.ArrayList;

import java.util.TreeMap;

 

public class Map {

Employee employees1[] = {

 

new Employee("12345", "Tom", "Baker", 200000),

new Employee("56789", "Dan", "Jones", 130000),

new Employee("24680", "Ann", "Scoot", 90000),

new Employee("13579", "Pat", "Jones", 200000),

new Employee("11111", "Bob", "Scott", 65000),

new Employee("23232", "Scott", "Baker", 65000),

new Employee("45454", "Amy", "Perez", 105000),

new Employee("67676", "Jones", "BakwJoneser", 140000)

 

};

 

// create an array list object that will hold data type = Employee

ArrayList<Employee> employeeList = new ArrayList <>();

// iterate the array and add the employee to the list

for (Employee employee1 : employees) {

//add employee1 to the employeeList

employeeList.add(employee1);

}

 

System.out.println("All Employee\n");

// use and enhanced for loop to print the employees

for (Employee employees : employeeList) {

System.out.println(employee1);

}

 

// create a tree map with String and Empolyee Objects

TreeMap<String,Employee> employeeTreeMap = new TreeMap<>();

for(Employee employee:employeeList){

//use for lope to add the employees to the TreeSet using put() method to get the employees IDs and Name

employeeTreeMap.put(employee1.getId(),employee1);

}

// print each employee sorted by employee id

System.out.println("Employees By ID #\n");

//iterate the tree map

for(String id: employeeTreeMap.keySet()){

//Print out employee names and ID with Tree Map

System.out.println(employeeTreeMap.get(id));

}

 

}

}

Employee Class 

package chapter21;
import java.text.DecimalFormat;
import java.text.NumberFormat;
 
public class Employee {
//Attributes (all private):
private String id;
private String lastName;
private String firstName;
private int salary;
 
// Methods 
Employee (String id, String lastName, String firstName, int salary) {
this.id = id; //pts to the data that is put into the constructor 
    this.lastName = lastName;
    this.firstName = firstName;
    this.salary = salary;
}
//Getters for all attributes
   public String getId() { //creates a method to return the data 
       return id; 
   }
   public String getLastName() {
       return lastName;
   }
   public String getFirstName() {
       return firstName;
   }
   public int getSalary() {
       return salary;
   }
 
// toString method to display an Employee's attributes (See output of executable below)
   //Define the method to return the employee details.
   @Override
   public String toString() {
      
       //Use number format and decimal format
       //to format the salary to desired output.
   //"ID 23232:Baker, Amy, salary $100,000"
   // "ID 12345:Jones, Dan, salary $200,000"
   //Number froamt returns a currency format 
       NumberFormat nfm = NumberFormat.getCurrencyInstance();
       //
       String pt = ((DecimalFormat) nfm).toPattern();
       //
       String npt = pt.replace("\u00A4", "").trim();
       //create varaible to hold decimal 
       NumberFormat nfm2 = new DecimalFormat(npt);
       //set to setMinimum to round up or down for miney format 
       nfm2.setMinimumFractionDigits(0);
      
       //return //"ID + 23232 + : + Baker,+ " , " + Amy +, salary $+ 100,000"
       return "ID " + id + ":" + lastName + ", " + firstName
                           + ", salary $" + nfm2.format(salary);
   }
}
 
 
Expert Solution
steps

Step by step

Solved in 6 steps with 3 images

Blurred answer
Knowledge Booster
Topological Sort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education