Created
January 23, 2017 19:09
-
-
Save RossignolVincent/5c1b8eee5417c050ad9d74c9c599c02a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ESGI; | |
/** | |
* Created by Vincent on 23/01/2017. | |
*/ | |
public class Activity { | |
String type; | |
int begin; | |
int end; | |
public Activity(String type, int begin, int end) { | |
this.type = type; | |
this.begin = begin; | |
this.end = end; | |
} | |
@Override | |
public String toString() { | |
return type + " : from " + begin + " to " + end; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ESGI; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Created by Vincent on 03/01/2017. | |
*/ | |
public class Affectation { | |
Worker worker; | |
String date; | |
String task; | |
public Affectation(Worker worker, String date, String task) { | |
this.worker = worker; | |
this.date = date; | |
this.task = task; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ESGI; | |
/** | |
* Created by Vincent on 23/01/2017. | |
*/ | |
public class CSVLog { | |
public Factory factory; | |
public CSVLog(Factory factory){ | |
this.factory = factory; | |
} | |
public void writeCSVLog(){ | |
for(Affectation affectation : factory.list) { | |
for(Activity activity : affectation.worker.activities){ | |
System.out.println(affectation.task+";"+affectation.date+";"+affectation.worker.name+";"+activity.type+";"+activity.begin+";"+activity.end); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ESGI; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Created by Vincent on 03/01/2017. | |
*/ | |
public class Factory { | |
public List<Affectation> list; | |
public Factory () { | |
list = new ArrayList<Affectation>(); | |
} | |
public void affect(Worker worker, String date, String task){ | |
for(Affectation a : list){ | |
if(worker.name.equals(a.worker.name)){ | |
a.date = date; | |
a.task = task; | |
return; | |
} | |
} | |
list.add(new Affectation(worker, date, task)); | |
} | |
public void task1(Worker worker, String date) { | |
affect(worker, date, "task1"); | |
} | |
public void task2(Worker worker, String date) { | |
affect(worker, date, "task2") ; | |
} | |
public void task3(Worker worker, String date){ | |
affect(worker, date, "task3"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ESGI; | |
/** | |
* Created by Vincent on 23/01/2017. | |
*/ | |
public class HumanWorker extends Worker { | |
public HumanWorker(String name){ | |
super(name); | |
} | |
@Override | |
public void work(int begin, int end) { | |
addActivity("work", begin, end); | |
} | |
public void eat(int begin, int end) { | |
addActivity("eat", begin, end); | |
} | |
public void sleep(int begin, int end) { | |
addActivity("sleep", begin, end); | |
} | |
public void other(int begin, int end) { | |
addActivity("other", begin, end); | |
} | |
public void addActivity(String type, int begin, int end){ | |
activities.add(new Activity(type, begin, end)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ESGI; | |
/* | |
https://gist.github.com/rhwy/dddf59092302df5b4a54951ab61576ca | |
https://gist.github.com/rhwy/077d216484487672fd3c029af4a601a2 | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
Factory factory = new Factory(); | |
HumanWorker Charles = new HumanWorker("Charles"); | |
factory.affect(Charles, "01/12/2017", "task1"); | |
Charles.work(8, 20); | |
Charles.sleep(20, 8); | |
RobotWorker BB8 = new RobotWorker("BB8"); | |
factory.affect(BB8, "01/12/2017", "task2"); | |
BB8.work(8, 20); | |
BB8.standby(20, 8); | |
CSVLog csvLog = new CSVLog(factory); | |
csvLog.writeCSVLog(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ESGI; | |
/** | |
* Created by Vincent on 23/01/2017. | |
*/ | |
public class RobotWorker extends Worker { | |
public RobotWorker(String name){ | |
super(name); | |
} | |
@Override | |
public void work(int begin, int end) { | |
addActivity("work", begin, end); | |
} | |
public void standby(int begin, int end) { | |
addActivity("standby", begin, end); | |
} | |
public void addActivity(String type, int begin, int end){ | |
activities.add(new Activity(type, begin, end)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ESGI; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Created by Vincent on 03/01/2017. | |
*/ | |
public abstract class Worker { | |
public String name; | |
public List<Activity> activities; | |
public Worker(String name) { | |
this.name = name; | |
activities = new ArrayList<Activity>(); | |
} | |
public abstract void work(int begin, int end); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment