diff --git a/src/tp04/PendingCaseQueue.java b/src/tp04/PendingCaseQueue.java new file mode 100644 index 0000000000000000000000000000000000000000..66045e88e560eb93f4b0d3f6521bc059c5a6c4c8 --- /dev/null +++ b/src/tp04/PendingCaseQueue.java @@ -0,0 +1,131 @@ +package tp04; + +import tpOO.tp04.PendingCase; + +public class PendingCaseQueue +{ + public static int CAPACITY = 10; + private int idx; + private PendingCase[] tableur; + + public PendingCaseQueue() + { + this.tableur = new PendingCase[CAPACITY]; + } + + public PendingCase removeOne() + { + PendingCase pc = null; + for(int i = 0; i < this.tableur.length; i++) + { + if(this.tableur[i] != null) + { + this.tableur[i] = pc; + break; + } + } + return pc; + } + + public void clear() + { + PendingCase pc = null; + for(int i = 0; i < this.tableur.length; i++) + { + if(this.tableur[i] != null) + { + this.tableur[i] = pc; + } + } + } + + public void cheating(PendingCase another, int position) + { + if(!isFull() && this.tableur[position] == null) + { + for(int i = 0; i < this.tableur.length; i++) + { + if(this.tableur[i] == another) + { + this.tableur[i] = null; + break; + } + } + this.tableur[position] = another; + } + } + + public double getTotalAmount() + { + double db = 0.0; + for(int i = 0; i < this.tableur.length; i++) + { + if(this.tableur[i] != null) + { + db = db + this.tableur[i].getAmount(); + } + } + return db; + } + + public void addOne(PendingCase other) + { + if(!isFull()) + { + for(int i = 0; i < this.tableur.length; i++) + { + if(this.tableur[i] == null) + { + this.tableur[i] = other; + break; + } + } + } + } + + + public boolean isEmpty() + { + int compteur = 0; + for(int i = 0; i < this.tableur.length; i++) + { + if(this.tableur[i] == null) + { + compteur = compteur + 1; + } + } + return this.tableur.length == compteur; + } + + public int size() + { + return CAPACITY; + } + + public boolean isFull() + { + int compteur = 0; + for(int i = 0; i < this.tableur.length; i++) + { + if(this.tableur[i] != null) + { + compteur = compteur + 1; + } + } + return CAPACITY == compteur; + } + + @Override + public String toString() + { + String str = ""; + for(int i = 0; i < CAPACITY; i++) + { + if(this.tableur[i] != null) + { + str=str+this.tableur[i].getCompany()+" "; + } + } + return str; + } +} \ No newline at end of file diff --git a/src/tp04/UsePendingCaseQueue.java b/src/tp04/UsePendingCaseQueue.java index a00c60cea385624beaea575ff8cde011968b7095..15406079d0cd68888038c53fbf75b5d77e159f81 100755 --- a/src/tp04/UsePendingCaseQueue.java +++ b/src/tp04/UsePendingCaseQueue.java @@ -1,8 +1,10 @@ package tp04; +import tpOO.tp04.PendingCase; + public class UsePendingCaseQueue { public static void main(String[] args) { - /* PendingCase pc1 = new PendingCase("Alice", "AAA", 1234.56); + PendingCase pc1 = new PendingCase("Alice", "AAA", 1234.56); PendingCase pc2 = new PendingCase("Bruno", "BBB", 0.42); PendingCase pc3 = new PendingCase("ChloƩ", "CCC", 745.99); PendingCase pc4 = new PendingCase("Denis", "DDD", 125.0); @@ -24,6 +26,15 @@ public class UsePendingCaseQueue { pcq.addOne(pc1); System.out.println("After addition of pc1: " + pcq); pcq.clear(); - System.out.println("After clearing: " + pcq);*/ //C PAS FINI MA COUILLE + System.out.println("After clearing: " + pcq); + pcq.addOne(pc1); + pcq.addOne(pc4); + pcq.addOne(pc3); + System.out.println("Ajout: " + pcq); + pcq.removeOne(); + System.out.println("Delete: " + pcq); + pcq.cheating(pc3, 0); + System.out.println("Cheat: " + pcq); + System.out.println("Total Amount: " + pcq.getTotalAmount()); } }