From 334a06aa83397380105f956cee3c46b5cdc85b33 Mon Sep 17 00:00:00 2001 From: Samuel Turpin <samuel.turpin.etu@univ-lille.fr> Date: Fri, 24 May 2024 09:18:08 +0200 Subject: [PATCH] =?UTF-8?q?tpOO-04::exo-contr=C3=B4le2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tp04/PendingCaseQueue.java | 131 ++++++++++++++++++++++++++++++ src/tp04/UsePendingCaseQueue.java | 15 +++- 2 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 src/tp04/PendingCaseQueue.java diff --git a/src/tp04/PendingCaseQueue.java b/src/tp04/PendingCaseQueue.java new file mode 100644 index 0000000..66045e8 --- /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 a00c60c..1540607 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()); } } -- GitLab