Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class Task {
- protected int timpExecutie;
- public int execute(){
- return timpExecutie;
- }
- public abstract String toString();
- }
- public class SimpleTask extends Task {
- SimpleTask(int timpEx){
- this.timpExecutie = timpEx;
- }
- @Override
- public String toString() {
- // TODO Auto-generated method stub
- return "Simple Task(" + this.timpExecutie + ")";
- }
- public void ChangeTime(int new_time){
- this.timpExecutie = new_time;
- }
- }
- public class ConditionalTask extends Task {
- private Task unu;
- private Task doi;
- ConditionalTask(Task unu, Task doi){
- this.unu = unu;
- this.doi = doi;
- int tmp = (int)Math.round(Math.random());
- this.timpExecutie = 5 + tmp*unu.execute() + (1 - tmp)*doi.execute();
- }
- public int getTask(){
- return 2;
- }
- @Override
- public String toString() {
- return "Contitional Task("+ unu +"," + doi + ")";
- }
- }
- public class BlockTask extends Task {
- private Task[] task = new Task[32];
- private int nrTask;
- public void insert(Task new_task){
- if (nrTask == task.length){ // marim tabloul
- Task[] newTask = new Task[nrTask * 2];
- for(int i = 0; i < nrTask; i++){
- newTask[i] = task[i];
- }
- task = newTask; //setem referinta
- }
- task[nrTask] = new_task; //adaugam
- nrTask++;
- this.timpExecutie += new_task.execute();//iserez unu ii cresc timpul de executie
- }
- public int getNrTask(){
- return nrTask;
- }
- @Override
- public String toString() {
- String s = "BlockTask(";
- for (int i = 0; i < nrTask; i++){
- s += task[i] +",";
- }
- s = s.substring(0, s.length()-1);
- return s + ")";
- }
- }
- public class Main {
- public static void main(String[] args) {
- SimpleTask s = new SimpleTask(165);
- BlockTask b = new BlockTask();
- b.insert(new SimpleTask(5));
- b.insert(new SimpleTask(4));
- ConditionalTask c = new ConditionalTask(s, b);
- System.out.println(c);
- System.out.println(c.getTask());
- System.out.println(b.getNrTask());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement