/* Array7.java CIS 160 11/01/04 using arrays of objects */ import java.io.*; import java.util.*; public class Array7 { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("people2.txt")); final int MAXSIZE = 100; int numRecs = 0; Employee[] emp = new Employee[MAXSIZE]; // read records into Employee array String s; s = in.readLine(); while (s != null) { if (numRecs < MAXSIZE) { emp[numRecs] = new Employee(s); numRecs++; } else { System.out.println("Error: Too many records in file"); break; } s = in.readLine(); } in.close(); // sort Employee array based on ID for (int i=0; i 0) { emp[i].swap(emp[j]); } } } // display records from arrays for (int i=0; i= 0) { if (sb.charAt(ndx) == '"') sb.deleteCharAt(ndx); ndx--; } setName(sb.toString().trim()); } } public void setID(int i) { if (i <= 0) i = -1; id = i; } public void setName(String s) { if (s == null) name = new String(""); else name = new String(s); } public int getID() { return id; } public String getName() { return name; } public int compareTo(Employee e) { if (id > e.id) return 1; if (id < e.id) return -1; return 0; } public void swap(Employee e) { int tmp = id; String stmp = name; id = e.id; name = e.name; e.id = tmp; e.name = stmp; } }