Revision: 34118
Updated Code
at November 19, 2010 20:10 by trusktr
Updated Code
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()); } public Employees(String f, String l, double hrs, double pr) { emps = new ArrayList<Employee>(); emps.add(new HourlyEmployee(f, l, hrs, pr)); } public Employees(MyString f, MyString l, Number hrs, Number 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); } public Employees(File file) { emps = new ArrayList<Employee>(); try { FileReader fr = null; BufferedReader br = null; fr = new FileReader(file); br = new BufferedReader(fr); 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 emps.add(new HourlyEmployee(de.get(0).toString(), de.get(1).toString(), Double.parseDouble(de.get(2).toString()), Double.parseDouble(de.get(3).toString()))); } br.close(); // dispose of the resources after using them. } catch (FileNotFoundException e) { // File not found. System.out.println("\n ####\n #### !!! The file could not be found. !!!\n ####"); } catch (IOException e) { // Error with transaction. System.out.println("\n ####\n #### !!! There was an error reading the file. !!!\n ####"); } } // ) // Accessors ( public Employee employee(int n) { return emps.get(n); // ########################################################### } // HOW TO RETURN NEW HOURLY EMPLOYEE ???????? public int size() { return emps.size(); } // ) // Mutators ( public void add(String f, String l, double pr, double hrs) { 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(MyString f, MyString l, Number pr, Number hrs) { 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); } public int remove(String last) { 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; } public int remove(String first, String last) { 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(); } public EmployeeData getInfo(String last) { 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 { System.out.println("Error: That employee doesn't exist."); } return info; } public EmployeeData getInfo(String first, String last) { 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 { System.out.println("Error: That employee doesn't exist."); } return info; } public void sort() { Collections.sort(emps); } public String toString() { return "You have " + emps.size() + " employees under your belt."; } // ) }
Revision: 34117
Updated Code
at October 17, 2010 15:23 by trusktr
Updated Code
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 Employee()); } public Employees(String f, String l, double pr, double hrs) { emps = new ArrayList<Employee>(); emps.add(new Employee(f, l, pr, hrs)); } public Employees(MyString f, MyString l, Number pr, Number hrs) { emps = new ArrayList<Employee>(); emps.add(new Employee(f, l, pr, hrs)); } public Employees(EmployeeData d) { emps = new ArrayList<Employee>(); emps.add(new Employee(d)); } public Employees(Employee e) { emps = new ArrayList<Employee>(); emps.add(new Employee(e)); } public Employees(Employees e) { emps = new ArrayList<Employee>(e.emps); } public Employees(File file) { emps = new ArrayList<Employee>(); FileReader fr = null; BufferedReader br = null; try { fr = new FileReader(file); br = new BufferedReader(fr); 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. DataReader dr = new DataReader(record); // For extracting data from a MyString. dr.setBuffer("|"); // Sets a buffer for accessing the data items deliminated by a space emps.add(new Employee(dr.get(0).toString(), dr.get(1).toString(), Double.parseDouble(dr.get(2).toString()), Double.parseDouble(dr.get(3).toString()))); } br.close(); // dispose of the resources after using them. } catch (FileNotFoundException e) { // File not found. // e.printStackTrace(); // uncomment to show the full exception error // Put something here like an error message. System.out.println("\n ####\n #### !!! The file could not be found. !!!\n ####"); } catch (IOException e) { // Error with transaction. // e.printStackTrace(); // uncomment to show the full exception error // Put something here like an error message. System.out.println("\n ####\n #### !!! There was an error reading the file. !!!\n ####"); } } // ) // Accessors ( public Employee employee(int n) { return new Employee(emps.get(n)); } public int size() { return emps.size(); } // ) // Mutators ( public void add(String f, String l, double pr, double hrs) { 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 Employee(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 Employee(f, l, pr, hrs)); // Otherwise just append the new employees to the list. } } else { emps.add(new Employee(f, l, pr, hrs)); // Otherwise just append the new employees to the list. } } public void add(MyString f, MyString l, Number pr, Number hrs) { 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 Employee(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 Employee(f, l, pr, hrs)); // Otherwise just append the new employees to the list. } } else { emps.add(new Employee(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 Employee(d)); // Then our Employee list contains a default employee in the first position that we need to overwrite. } else { emps.add(new Employee(d)); // Otherwise just append the new employees to the list. } } else { emps.add(new Employee(d)); // Otherwise just append the new employees to the list. } } public void add(Employee 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 Employee(e)); // Then our Employee list contains a default employee in the first position that we need to overwrite. } else { emps.add(new Employee(e)); // Otherwise just append the new employee to the list. } } else { emps.add(new Employee(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, new Employee(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(new Employee(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(new Employee(e.emps.get(i-this.emps.size()))); // SHOULD I USE THE NEW CALL??????? //########################################################################### } } } public void remove(int n) { emps.remove(n); } public int remove(String last) { 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; } public int remove(String first, String last) { 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(); } public EmployeeData getInfo(String last) { 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 { System.out.println("Error: That employee doesn't exist."); } return info; } public EmployeeData getInfo(String first, String last) { 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 { System.out.println("Error: That employee doesn't exist."); } return info; } public void sort() { Collections.sort(emps); } public String toString() { return "You have " + emps.size() + " employees under your belt."; } // ) }
Revision: 34116
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 17, 2010 12:04 by trusktr
Initial Code
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 Employee()); } public Employees(String f, String l, double pr, double hrs) { emps = new ArrayList<Employee>(); emps.add(new Employee(f, l, pr, hrs)); } public Employees(MyString f, MyString l, Number pr, Number hrs) { emps = new ArrayList<Employee>(); emps.add(new Employee(f, l, pr, hrs)); } public Employees(EmployeeData d) { emps = new ArrayList<Employee>(); emps.add(new Employee(d)); } public Employees(Employee e) { emps = new ArrayList<Employee>(); emps.add(new Employee(e)); } public Employees(Employees e) { emps = new ArrayList<Employee>(e.emps); } public Employees(File file) { emps = new ArrayList<Employee>(); FileReader fr = null; BufferedReader br = null; try { fr = new FileReader(file); br = new BufferedReader(fr); 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. DataReader dr = new DataReader(record); // For extracting data from a MyString. dr.setBuffer("|"); // Sets a buffer for accessing the data items deliminated by a space emps.add(new Employee(dr.get(0).toString(), dr.get(1).toString(), Double.parseDouble(dr.get(2).toString()), Double.parseDouble(dr.get(3).toString()))); } br.close(); // dispose of the resources after using them. } catch (FileNotFoundException e) { // File not found. // e.printStackTrace(); // uncomment to show the full exception error // Put something here like an error message. System.out.println("\n ####\n #### !!! The file could not be found. !!!\n ####"); } catch (IOException e) { // Error with transaction. // e.printStackTrace(); // uncomment to show the full exception error // Put something here like an error message. System.out.println("\n ####\n #### !!! There was an error reading the file. !!!\n ####"); } } // ) // Accessors ( public Employee employee(int n) { return new Employee(emps.get(n)); } public int size() { return emps.size(); } // ) // Mutators ( public void add(String f, String l, double pr, double hrs) { 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 Employee(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 Employee(f, l, pr, hrs)); // Otherwise just append the new employees to the list. } } else { emps.add(new Employee(f, l, pr, hrs)); // Otherwise just append the new employees to the list. } } public void add(MyString f, MyString l, Number pr, Number hrs) { 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 Employee(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 Employee(f, l, pr, hrs)); // Otherwise just append the new employees to the list. } } else { emps.add(new Employee(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 Employee(d)); // Then our Employee list contains a default employee in the first position that we need to overwrite. } else { emps.add(new Employee(d)); // Otherwise just append the new employees to the list. } } else { emps.add(new Employee(d)); // Otherwise just append the new employees to the list. } } public void add(Employee 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 Employee(e)); // Then our Employee list contains a default employee in the first position that we need to overwrite. } else { emps.add(new Employee(e)); // Otherwise just append the new employee to the list. } } else { emps.add(new Employee(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, new Employee(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(new Employee(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(new Employee(e.emps.get(i-this.emps.size()))); // SHOULD I USE THE NEW CALL??????? //########################################################################### } } } public void remove(int n) { emps.remove(n); } public int remove(String last) { 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; } public int remove(String first, String last) { 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(); } public EmployeeData getInfo(String last) { 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 { System.out.println("Error: That employee doesn't exist."); } return info; } public EmployeeData getInfo(String first, String last) { 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 { System.out.println("Error: That employee doesn't exist."); } return info; } public void sort() { Collections.sort(emps); } public String toString() { return "You have " + emps.size() + " employees under your belt."; } // ) }
Initial URL
Initial Description
Initial Title
CISP401 Employees.java
Initial Tags
java
Initial Language
Java