Skip to content
Snippets Groups Projects
Commit 334a06aa authored by Samuel Turpin's avatar Samuel Turpin :computer:
Browse files

tpOO-04::exo-contrôle2

parent 854f6072
Branches
No related tags found
No related merge requests found
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
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());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment