empID cannot be resolved or is not a field
in
Programming Questions
•
2 years ago
How, every tutorial i try ends up in not working, i thought
processing was basicly java.
I get empID cannot be resolved or is not a field
The error brings me to a empty line instand of a line where you can read empID.
And i never mistyped empID...
- import java.util.*;
- class TestEmployeeSort{
- public static void main(String[] args) {
- List coll = Util.getEmployees();
- Collections.sort(coll); // sort method
- printList(coll);
- }
- private static void printList(List<Employee> list) {
- println("EmpId\tName\tAge");
- for (Employee e: list) {
- println(e.getEmpId() + "\t" + e.getName() + "\t" + e.getAge());
- }
- }
- }
- public class Util {
- List<Employee> getEmployees() {
- List<Employee> col = new ArrayList<Employee>();
- col.add(new Employee(5, "Frank", 28));
- col.add(new Employee(1, "Jorge", 19));
- col.add(new Employee(6, "Bill", 34));
- col.add(new Employee(3, "Michel", 10));
- col.add(new Employee(7, "Simpson", 8));
- col.add(new Employee(4, "Clerk",16 ));
- col.add(new Employee(8, "Lee", 40));
- col.add(new Employee(2, "Mark", 30));
- return col;
- }
- }
- void setup() {
- }
- void draw() {
- }
- class Employee implements Comparable<Employee> {
- int empId;
- String name;
- int age;
- Employee(int empId, String name, int age) {
- this.empId = empId;
- this.name = name;
- this.age = age;
- // set values on attributes
- }
- // getters & setters
- public int compareTo(Employee o){
- return this.empID - o.empID;
- }
- }
1
