diff --git a/build/classes/turncontrol/Employee.class b/build/classes/turncontrol/Employee.class index 2dd8327..ca56ac2 100644 Binary files a/build/classes/turncontrol/Employee.class and b/build/classes/turncontrol/Employee.class differ diff --git a/build/classes/turncontrol/TurnControl.class b/build/classes/turncontrol/TurnControl.class index 3aec2f3..20dbd23 100644 Binary files a/build/classes/turncontrol/TurnControl.class and b/build/classes/turncontrol/TurnControl.class differ diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 691e469..8cae265 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -4,7 +4,9 @@ file:/C:/Users/nhuyt/OneDrive/Documents/NetBeansProjects/TurnControl/src/turncontrol/Employee.java + file:/C:/Users/nhuyt/OneDrive/Documents/NetBeansProjects/TurnControl/src/turncontrol/test1.java file:/C:/Users/nhuyt/OneDrive/Documents/NetBeansProjects/TurnControl/src/turncontrol/TurnControl.java + file:/C:/Users/nhuyt/OneDrive/Documents/NetBeansProjects/TurnControl/src/turncontrol/BubbleSort.java diff --git a/src/turncontrol/BubbleSort.java b/src/turncontrol/BubbleSort.java index 1633627..6cab77b 100644 --- a/src/turncontrol/BubbleSort.java +++ b/src/turncontrol/BubbleSort.java @@ -17,44 +17,75 @@ public class BubbleSort { public void bubbleSortTime(ArrayList employee) { int n = employee.size(); + System.out.println("BEFORE bubbleSortTime:"); + printEmployeeName(employee); for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { - if (employee.get(i).getCheckInTime().isAfter(employee.get(i + 1).getCheckInTime())) { - Collections.swap(employee, i, i + 1); + if (employee.get(j).getCheckInTime().isAfter(employee.get(j + 1).getCheckInTime())) { + System.out.print("<>"); + Collections.swap(employee, j, j + 1); } } + System.out.println("bubbleSortTime-SORT ROUND " + (i + 1)); } + System.out.println("AFTER bubbleSortTime:"); + printEmployeeName(employee); } public void bubbleSortTotal(ArrayList employee) { int n = employee.size(); + System.out.println("BEFORE bubbleSortTotal:"); + printEmployeeName(employee); for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { - if (employee.get(i).getTotal() > employee.get(i + 1).getTotal()) { - Collections.swap(employee, i, i + 1); + if (employee.get(j).getTotal() > employee.get(j + 1).getTotal()) { + System.out.print("<>"); + Collections.swap(employee, j, j + 1); + } else if (employee.get(j).getTotal() == employee.get(j + 1).getTotal()) { + if (employee.get(j).getCheckInTime().isAfter(employee.get(j + 1).getCheckInTime())) { + System.out.print("<>"); + Collections.swap(employee, j, j + 1); + } } } + System.out.println("bubbleSortTotal-SORT ROUND " + (i + 1)); } + System.out.println("AFTER bubbleSortTotal:"); + printEmployeeName(employee); } public void bubbleSortTotalTurn(ArrayList employee) { int n = employee.size(); + System.out.println("BEFORE bubbleSortTotalTurn:"); + printEmployeeName(employee); for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { - if (employee.get(i).getTotalTurn()> employee.get(i + 1).getTotalTurn()) { - Collections.swap(employee, i, i + 1); + if (employee.get(j).getTotalTurn() > employee.get(j + 1).getTotalTurn()) { + System.out.print("<>"); + Collections.swap(employee, j, j + 1); + } else if (employee.get(j).getTotalTurn() == employee.get(j + 1).getTotalTurn()) { + if (employee.get(j).getCheckInTime().isAfter(employee.get(j + 1).getCheckInTime())) { + Collections.swap(employee, j, j + 1); + } } } + System.out.println("bubbleSortTotalTurn-SORT ROUND " + (i + 1)); + printEmployeeList(employee); } + System.out.println("AFTER bubbleSortTotalTurn:"); + printEmployeeName(employee); } - /* Prints the array */ - public void printArray(int arr[]) { - int n = arr.length; - for (int i = 0; i < n; ++i) { - System.out.print(arr[i] + " "); + public static void printEmployeeList(ArrayList e) { + for (int i = 0; i < e.size(); i++) { + System.out.println("Employee " + e.get(i).getEmpName() + " ----Total Turn " + e.get(i).getTotalTurn()); + } + } + + public static void printEmployeeName(ArrayList e) { + for (int i = 0; i < e.size(); i++) { + System.out.println(e.get(i).getEmpName() + "\t" + e.get(i).getTotalTurn() + "\t" + + e.get(i).getCheckInTime().toString()); } - System.out.println(); } } -/* This code is contributed by Rajat Mishra */ diff --git a/src/turncontrol/Employee.java b/src/turncontrol/Employee.java index 715c821..d7bcaa7 100644 --- a/src/turncontrol/Employee.java +++ b/src/turncontrol/Employee.java @@ -23,11 +23,20 @@ public class Employee { int position; boolean active; boolean isWorking; + int indexGroup; Employee() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + public int getIndexGroup() { + return indexGroup; + } + + public void setIndexGroup(int indexGroup) { + this.indexGroup = indexGroup; + } + public boolean isIsWorking() { return isWorking; } diff --git a/src/turncontrol/TurnControl.java b/src/turncontrol/TurnControl.java index 0774275..e92b6aa 100644 --- a/src/turncontrol/TurnControl.java +++ b/src/turncontrol/TurnControl.java @@ -3,12 +3,13 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.Scanner; /** * - * @author nhuytan - * add collaborator lanhsunam987 + * @author nhuytan add collaborator lanhsunam987 */ public class TurnControl { @@ -25,8 +26,8 @@ public static void main(String[] args) { TableBuilder tbCommandGuide = new TableBuilder(); tbCommandGuide.addRow("Enter Command: ", "=========", "========="); tbCommandGuide.addRow("1-Check In", "2-Check Out", "e-Exit Program"); - tbCommandGuide.addRow("p-Print List", "3-Add Turn", "4-Remove Turn"); - tbCommandGuide.addRow("5-Revert Working Status", "6-Update Turn", "----"); + tbCommandGuide.addRow("3-Add Turn", "4-Remove Turn","5-Revert Working Status"); + tbCommandGuide.addRow("6-Update Turn", "p-print"); String commandGuide = tbCommandGuide.toString(); while (true) { @@ -376,12 +377,19 @@ public static void print(ArrayList employee) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm:ss"); System.out.println("\nEmployee Table Details:"); TableBuilder tb = new TableBuilder(); - tb.addRow("EmployeeID", "EmployeeName", "CheckInTime", "Total", "Total_Turn", "Is_Working", "Status", "Position", "Turn_List"); + tb.addRow("EmployeeID", "EmployeeName", "CheckInTime", "Total", "Total_Turn", "Is_Working", "Status", "Position", "Turn_List", "Index_Group"); //System.out.println("EmployeeID\tEmployeeName\tCheckInTime\tTotal\tStatus\tPosition\n"); for (int i = 0; i < employee.size(); i++) { int index = getIndexByValue(employee, i + 1); String turnList = getStringTurn(employee.get(index)); - tb.addRow(employee.get(index).getEmployeeID(), employee.get(index).getEmpName(), dtf.format(employee.get(index).getCheckInTime()), Integer.toString(employee.get(index).getTotal()), Integer.toString(employee.get(index).getTotalTurn()), Boolean.toString(employee.get(index).isIsWorking()), Boolean.toString(employee.get(index).isActive()), Integer.toString(employee.get(index).position), turnList); + tb.addRow(employee.get(index).getEmployeeID(), employee.get(index).getEmpName(), + dtf.format(employee.get(index).getCheckInTime()), + Integer.toString(employee.get(index).getTotal()), + Integer.toString(employee.get(index).getTotalTurn()), + Boolean.toString(employee.get(index).isIsWorking()), + Boolean.toString(employee.get(index).isActive()), + Integer.toString(employee.get(index).position), turnList, + Integer.toString(employee.get(index).getIndexGroup())); } System.out.println(tb.toString()); } @@ -426,7 +434,7 @@ public static void print(ArrayList employee, boolean status) { TableBuilder tb = new TableBuilder(); tb.addRow("EmployeeID", "EmployeeName", "CheckInTime", "Total", "Total_Turn", "Is_Working", "Status", "Position", "Turn_List"); for (int i = 0; i < tmpInActive.size(); i++) { - int index = getIndexByValue(tmpInActive, employee.size()-tmpInActive.size() + 1); + int index = getIndexByValue(tmpInActive, employee.size() - tmpInActive.size() + 1); String turnList = getStringTurn(tmpInActive.get(index)); tb.addRow(tmpInActive.get(index).getEmployeeID(), tmpInActive.get(index).getEmpName(), @@ -442,7 +450,7 @@ public static void print(ArrayList employee, boolean status) { } } -// HELP FUNCTIO - UPDATE POSITION BASE ON: TOTALTURN, CHECK-IN TIME +// HELP FUNCTION - UPDATE POSITION BASE ON: TOTALTURN, CHECK-IN TIME /* Pseudo Code: 1. Count number of member (active+inactive) @@ -461,6 +469,8 @@ public static void updatePosition(ArrayList employee) { int numberActive = 0; int numberInActive = 0; int numberBusyWorker = 0; + int numberFreeWorker = 0; + BubbleSort b = new BubbleSort(); for (int i = 0; i < numberOfEmployee; i++) { if (employee.get(i).isActive()) { numberActive++; @@ -471,46 +481,99 @@ public static void updatePosition(ArrayList employee) { numberInActive++; } } -// create tmp array of inactive and sort inactive & index position - ArrayList tmpInActive = new ArrayList<>(numberInActive); - for (int i = 0; i < employee.size(); i++) { - if (employee.get(i).isActive() == false) { - tmpInActive.add(employee.get(i)); - } - } + numberFreeWorker = numberActive - numberBusyWorker; - BubbleSort b = new BubbleSort(); - b.bubbleSortTime(tmpInActive); - - for (int i = 0; i < tmpInActive.size(); i++) { - tmpInActive.get(i).setPosition(i + 1 + numberActive); + //System.out.println("employee object address is: "+ employee.); +//Create tmp array of inactive and sort inactive & index position +//Process Inactive worker array + if (numberInActive > 0) { + ArrayList tmpInActive = new ArrayList<>(numberInActive); + for (int i = 0; i < employee.size(); i++) { + if (employee.get(i).isActive() == false) { + tmpInActive.add(employee.get(i)); + } + } + b.bubbleSortTime(tmpInActive); + for (int i = 0; i < tmpInActive.size(); i++) { + tmpInActive.get(i).setPosition(i + 1 + numberActive); + } } // Create tmp array of busy worker and sort by total , index position - ArrayList tmpBusyWorker = new ArrayList<>(numberBusyWorker); - for (int i = 0; i < employee.size(); i++) { - if (employee.get(i).isActive() && employee.get(i).isIsWorking()) { - tmpBusyWorker.add(employee.get(i)); +// Process Busy worker array + if (numberBusyWorker > 0) { + ArrayList tmpBusyWorker = new ArrayList<>(numberBusyWorker); + for (int i = 0; i < employee.size(); i++) { + if (employee.get(i).isActive() && employee.get(i).isIsWorking()) { + tmpBusyWorker.add(employee.get(i)); + } + } + b.bubbleSortTotal(tmpBusyWorker); +//set Position + for (int i = 0; i < tmpBusyWorker.size(); i++) { + tmpBusyWorker.get(i).setPosition(numberActive - numberBusyWorker + i + 1); } - } - - b.bubbleSortTotal(tmpBusyWorker); - - for (int i = 0; i < tmpBusyWorker.size(); i++) { - tmpBusyWorker.get(i).setPosition(numberActive - numberBusyWorker + i + 1); } // 9 active , 4 working, 2 inactive --> free = 5, busy =5, inactive =2 // Create active list and not busy, sort and index - ArrayList tmpFreeWorker = new ArrayList<>(numberActive - numberBusyWorker); - for (int i = 0; i < employee.size(); i++) { - if (employee.get(i).isActive() && !employee.get(i).isIsWorking()) { - tmpFreeWorker.add(employee.get(i)); +// Process Free worker array + + if (numberFreeWorker > 0) { + ArrayList tmpFreeWorker = new ArrayList<>(numberFreeWorker); + for (int i = 0; i < employee.size(); i++) { + if (employee.get(i).isActive() && !employee.get(i).isIsWorking()) { + tmpFreeWorker.add(employee.get(i)); + } } - } - b.bubbleSortTotalTurn(tmpFreeWorker); + b.bubbleSortTotalTurn(tmpFreeWorker); +//index group by Step_Turn + int tmpIndexGroup = 1; + if (tmpFreeWorker.size() > 0) { + tmpFreeWorker.get(0).setIndexGroup(tmpIndexGroup); + //System.out.println("Employee: " + tmpFreeWorker.get(0).getEmpName() + " total_Turn: " + tmpFreeWorker.get(0).getTotalTurn()); + if (tmpFreeWorker.size() > 1) { + for (int i = 1; i < tmpFreeWorker.size(); i++) { + if ((tmpFreeWorker.get(i).getTotalTurn() - tmpFreeWorker.get(i - 1).getTotalTurn()) >= 15) { + tmpIndexGroup++; + tmpFreeWorker.get(i).setIndexGroup(tmpIndexGroup); + } else { + tmpFreeWorker.get(i).setIndexGroup(tmpIndexGroup); + } + //System.out.println("Employee: " + tmpFreeWorker.get(i).getEmpName() + " total_Turn: " + tmpFreeWorker.get(i).getTotalTurn()); + } + } + } - for (int i = 0; i < tmpFreeWorker.size(); i++) { - tmpFreeWorker.get(i).setPosition(i + 1); + ArrayList> arraylist_employee = new ArrayList>(tmpIndexGroup); + if (tmpFreeWorker.size() > 1) { + ArrayList tmp = new ArrayList(); + tmp.add(tmpFreeWorker.get(0)); + //int tmp = tmpFreeWorker.get(0).getIndexGroup(); + for (int i = 1; i < tmpFreeWorker.size(); i++) { + if (tmpFreeWorker.get(i).getIndexGroup() != tmpFreeWorker.get(i - 1).getIndexGroup()) { + arraylist_employee.add(tmp); + System.out.println("Added group: " + arraylist_employee.size() + " && with " + tmp.size() + " elements"); + tmp = new ArrayList(); + tmp.add(tmpFreeWorker.get(i)); + //arraylist_employee.get(index).add(tmpFreeWorker.get(i)); + } else { + tmp.add(tmpFreeWorker.get(i)); + //arraylist_employee.get(index).add(tmpFreeWorker.get(i)); + } + } + arraylist_employee.add(tmp); + System.out.println("Added last group: " + arraylist_employee.size() + " && with " + tmp.size() + " elements"); + + } + + for (int i = 0; i < arraylist_employee.size(); i++) { + int position = 1; + b.bubbleSortTime(arraylist_employee.get(i)); + for (int j = 0; j < arraylist_employee.get(i).size(); j++) { + arraylist_employee.get(i).get(j).setPosition(position); + position++; + } + } } } diff --git a/src/turncontrol/ngoiloinhapthe.html b/src/turncontrol/ngoiloinhapthe.html deleted file mode 100644 index 5a3f2aa..0000000 --- a/src/turncontrol/ngoiloinhapthe.html +++ /dev/null @@ -1,24 +0,0 @@ - -Linh Mục & Phó Tế

Linh Mục Gioan Vianney Nguyễn Ngọc Thụ
Cha Chánh Xứ
Liên Lạc:  281.495.8133

Phó Tế Guise Nguyễn Sĩ Bạch    
Liên Lạc: bachsinguyen@gmail.com

Linh Mục và Phó Tế Giáo Xứ

Phó Tế Nguyễn Đức Cường    
Liên Lạc:  cdnguyen7@yahoo.com 

8503 S. KIRKWOOD HOUSTON TX 77099

Tel. 281.495.8133 Fax 281.568.1833 

info@giaoxungoiloi.org

Linh Mục Giuse Bùi Phương Tiến   
Cha Phó Xứ
Liên Lạc:  281.495.8133

\ No newline at end of file diff --git a/src/turncontrol/test1.java b/src/turncontrol/test1.java index 0f7de07..c83d93d 100644 --- a/src/turncontrol/test1.java +++ b/src/turncontrol/test1.java @@ -1,111 +1,133 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package turncontrol; - -import java.time.LocalDateTime; -import java.util.ArrayList; - -/** - * - * @author nhuytan - * edit 1 - */ -public class test1 { - - public String EmployeeID; - public String EmpName; - LocalDateTime CheckInTime; - public ArrayList turnList; - int totalTurn, Total; - int position; - boolean active; - boolean isWorking; - - public boolean isIsWorking() { - return isWorking; - } - - public void setIsWorking(boolean isWorking) { - this.isWorking = isWorking; - } - - - public boolean isActive() { - return active; - } - - public void setActive(boolean active) { - this.active = active; - } - - - public String getEmployeeID() { - return EmployeeID; - } - - public void setEmployeeID(String EmployeeID) { - this.EmployeeID = EmployeeID; - } - - public String getEmpName() { - return EmpName; - } - - public void setEmpName(String EmpName) { - this.EmpName = EmpName; - } - - public LocalDateTime getCheckInTime() { - return CheckInTime; - } - - /** - * - * @param CheckInTime - */ - public void setCheckInTime(LocalDateTime CheckInTime) { - this.CheckInTime = CheckInTime; - } - - public test1(String EmployeeID, String EmpName, LocalDateTime CheckInTime) { - this.EmployeeID = EmployeeID; - this.EmpName = EmpName; - this.CheckInTime = CheckInTime; - this.Total=0; - this.totalTurn=0; - this.turnList = new ArrayList<>(); - this.active=true; - this.isWorking = false; - this.position= Integer.parseInt(EmployeeID); - - } - - public int getTotalTurn() { - return totalTurn; - } - - public void setTotalTurn(int TotalTurn) { - this.totalTurn = TotalTurn; - } - - public int getTotal() { - return Total; - } - - public void setTotal(int Total) { - this.Total = Total; - } - - public int getPosition() { - return position; - } - - public void setPosition(int position) { - this.position = position; - } - - -} +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package turncontrol; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Collections; + +/** + * + * @author nhuytan + * edit 1 + */ +public class test1 { + + public String EmployeeID; + public String EmpName; + LocalDateTime CheckInTime; + public ArrayList turnList; + int totalTurn, Total; + int position; + boolean active; + boolean isWorking; + + public boolean isIsWorking() { + return isWorking; + } + + public void setIsWorking(boolean isWorking) { + this.isWorking = isWorking; + } + + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + + public String getEmployeeID() { + return EmployeeID; + } + + public void setEmployeeID(String EmployeeID) { + this.EmployeeID = EmployeeID; + } + + public String getEmpName() { + return EmpName; + } + + public void setEmpName(String EmpName) { + this.EmpName = EmpName; + } + + public LocalDateTime getCheckInTime() { + return CheckInTime; + } + + /** + * + * @param CheckInTime + */ + public void setCheckInTime(LocalDateTime CheckInTime) { + this.CheckInTime = CheckInTime; + } + + public test1(String EmployeeID, String EmpName, LocalDateTime CheckInTime) { + this.EmployeeID = EmployeeID; + this.EmpName = EmpName; + this.CheckInTime = CheckInTime; + this.Total=0; + this.totalTurn=0; + this.turnList = new ArrayList<>(); + this.active=true; + this.isWorking = false; + this.position= Integer.parseInt(EmployeeID); + + } + + public int getTotalTurn() { + return totalTurn; + } + + public void setTotalTurn(int TotalTurn) { + this.totalTurn = TotalTurn; + } + + public int getTotal() { + return Total; + } + + public void setTotal(int Total) { + this.Total = Total; + } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public void testSwap() + { + ArrayList employee = new ArrayList<>(20); + System.out.println("employee adress " + System.identityHashCode(employee)); + // begin test + Employee e1 = new Employee("1","tan",LocalDateTime.now()); + System.out.println("e1 address " + System.identityHashCode(e1)); + Employee e2 = new Employee("2","loc",LocalDateTime.now()); + System.out.println("e2 address " + System.identityHashCode(e2)); + + employee.add(e1); + employee.add(e2); + System.out.println("e1 address after add " + System.identityHashCode(employee.get(0))); + System.out.println("e2 address adter add" + System.identityHashCode(employee.get(1))); + + //swap + Collections.swap(employee, 0, 1); + System.out.println("address after swap 0 " + System.identityHashCode(employee.get(0))); + System.out.println("address after swap 1 " + System.identityHashCode(employee.get(1))); + //end test + } + +}