/ Published in: Java
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import java.util.*; //ArrayLists, Comparable, Collections.sort() ... import java.io.*; public class Employees { // Data Objects ( private ArrayList<Employee> emps; // ) // Constructors ( public Employees() { emps = new ArrayList<Employee>(); emps.add(new HourlyEmployee()); } emps = new ArrayList<Employee>(); emps.add(new HourlyEmployee(f, l, hrs, pr)); } emps = new ArrayList<Employee>(); emps.add(new HourlyEmployee(f, l, hrs, pr)); } public Employees(EmployeeData d) { emps = new ArrayList<Employee>(); emps.add(new HourlyEmployee(d)); } public Employees(HourlyEmployee e) { emps = new ArrayList<Employee>(); emps.add(new HourlyEmployee(e)); } public Employees(Employees e) { emps = new ArrayList<Employee>(e.emps); } emps = new ArrayList<Employee>(); try { while (br.ready()) { // br.read() returns false when the Buffer is not ready (end of file). MyString record = new MyString("" + br.readLine()); // Only use reaLine() once inside the while loop or you will process more than one line per iteration. DataExtractor de = new DataExtractor(record); // For extracting data from a MyString. de.setBuffer("|"); // Sets a buffer for accessing the data items deliminated by a space } br.close(); // dispose of the resources after using them. } } } } // ) // Accessors ( public Employee employee(int n) { return emps.get(n); // ########################################################### } // HOW TO RETURN NEW HOURLY EMPLOYEE ???????? public int size() { return emps.size(); } // ) // Mutators ( if (emps.size()!=0) { EmployeeData tmp = emps.get(0).info(); if (tmp.first.has("x") && tmp.first.length()==1 && tmp.last.has("x") && tmp.last.length()==1) { // If first and last are "x" emps.set(0, new HourlyEmployee(f, l, pr, hrs)); // Then our Employee list contains a default employee in the first position that we need to overwrite. } else { emps.add(new HourlyEmployee(f, l, pr, hrs)); // Otherwise just append the new employees to the list. } } else { emps.add(new HourlyEmployee(f, l, pr, hrs)); // Otherwise just append the new employees to the list. } } if (emps.size()!=0) { EmployeeData tmp = emps.get(0).info(); if (tmp.first.has("x") && tmp.first.length()==1 && tmp.last.has("x") && tmp.last.length()==1) { // If first and last are "x" emps.set(0, new HourlyEmployee(f, l, pr, hrs)); // Then our Employee list contains a default employee in the first position that we need to overwrite. } else { emps.add(new HourlyEmployee(f, l, pr, hrs)); // Otherwise just append the new employees to the list. } } else { emps.add(new HourlyEmployee(f, l, pr, hrs)); // Otherwise just append the new employees to the list. } } public void add(EmployeeData d) { if (emps.size()!=0) { EmployeeData tmp = emps.get(0).info(); if (tmp.first.has("x") && tmp.first.length()==1 && tmp.last.has("x") && tmp.last.length()==1) { // If first and last are "x" emps.set(0, new HourlyEmployee(d)); // Then our Employee list contains a default employee in the first position that we need to overwrite. } else { emps.add(new HourlyEmployee(d)); // Otherwise just append the new employees to the list. } } else { emps.add(new HourlyEmployee(d)); // Otherwise just append the new employees to the list. } } public void add(HourlyEmployee e) { if (emps.size()!=0) { EmployeeData tmp = emps.get(0).info(); if (tmp.first.has("x") && tmp.first.length()==1 && tmp.last.has("x") && tmp.last.length()==1) { // If first and last are "x" emps.set(0, new HourlyEmployee(e)); // Then our Employee list contains a default employee in the first position that we need to overwrite. } else { emps.add(new HourlyEmployee(e)); // Otherwise just append the new employee to the list. } } else { emps.add(new HourlyEmployee(e)); // Otherwise just append the new employee to the list. } } public void add(Employees e) { if (emps.size()!=0) { EmployeeData tmp = emps.get(0).info(); if (tmp.first.has("x") && tmp.first.length()==1 && tmp.last.has("x") && tmp.last.length()==1) { // If first and last are "x" for (int i=0; i<e.emps.size(); i++) { // Then our Employee list is default so we can overwrite it with the new list. emps.set(i, e.emps.get(i)); // SHOULD I USE THE NEW CALL??????? //########################################################################### } } else { for (int i=this.emps.size(); i<this.emps.size()+e.emps.size(); i++) { // Otherwise just append the new employees to the list. emps.add(e.emps.get(i-this.emps.size())); // SHOULD I USE THE NEW CALL??????? //########################################################################### } } } else { for (int i=this.emps.size(); i<this.emps.size()+e.emps.size(); i++) { // Otherwise just append the new employees to the list. emps.add(e.emps.get(i-this.emps.size())); // SHOULD I USE THE NEW CALL??????? //########################################################################### } } } public void remove(int n) { emps.remove(n); } int status = 0; if (emps.size()!=0) { for(int i=0; i<emps.size(); i++) { EmployeeData tmp = emps.get(i).info(); if(tmp.last.has(last) && tmp.last.length()==last.length()) { emps.remove(i); } break; } } else { status = 1; } return status; } int status = 0; if (emps.size()!=0) { for(int i=0; i<emps.size(); i++) { EmployeeData tmp = emps.get(i).info(); if(tmp.last.has(last) && tmp.last.length()==last.length()) { if(tmp.first.has(first) && tmp.first.length()==first.length()) { emps.remove(i); } } break; } } else { status = 1; } return status; } public EmployeeData getInfo(int n) { return emps.get(n).info(); } EmployeeData info = new EmployeeData(); if (emps.size()!=0) { for(int i=0; i<emps.size(); i++) { EmployeeData tmp = emps.get(i).info(); if(tmp.last.has(last) && tmp.last.length()==last.length()) { info = new EmployeeData(emps.get(i).info()); } break; } } else { } return info; } EmployeeData info = new EmployeeData(); if (emps.size()!=0) { for(int i=0; i<emps.size(); i++) { EmployeeData tmp = emps.get(i).info(); if(tmp.last.has(last) && tmp.last.length()==last.length()) { if(tmp.first.has(first) && tmp.first.length()==first.length()) { info = new EmployeeData(emps.get(i).info()); } } break; } } else { } return info; } public void sort() { } return "You have " + emps.size() + " employees under your belt."; } // ) }