1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
|
import java.io.*;
import java.util.*;
class IN {
public static String getString() {
BufferedReader fe = new BufferedReader(new InputStreamReader(System.in));
boolean erreur;
String lu = null;
do {
try {
erreur = false;
lu = fe.readLine();
}
catch (IOException e) {
System.out.println("Recommencez.");
erreur = true;
}
} while (erreur);
return lu;
}
public static char getChar() {
String lu;
boolean erreur;
do {
lu = getString();
erreur = lu.equals("");
} while (erreur);
return lu.charAt(0);
}
public static int getInt() {
boolean erreur;
int lu = 0;
do {
try {
erreur = false;
lu = new Integer(getString()).intValue();
}
catch (NumberFormatException e) {
System.out.println("Veuillez entrer un entier!");
erreur = true;
}
} while (erreur);
return lu;
}
public static double getDouble() {
boolean erreur;
double lu = 0;
do {
try {
erreur = false;
lu = new Double(getString()).doubleValue();
}
catch (NumberFormatException e) {
System.out.println("Veuillez entrer un flottant!");
erreur = true;
}
} while (erreur);
return lu;
}
public static float getFloat() {
return (float)getDouble();
}
}
abstract class Contrainte
implements Serializable
{
protected Tache laTache;
protected int delai;
public Contrainte(Tache t) {
laTache = t;
delai = 0;
}
public Contrainte(Tache t, int d) {
laTache = t;
delai = d;
}
public Tache laTache() {
return laTache;
}
public void delai(int d) {
delai = d;
}
public int delai() {
return delai;
}
abstract public int debut();
abstract public String description();
}
class CalendrierSemaines{
int nbannees;
Calendar cal;
ArrayList semaines;
public CalendrierSemaines(int n){
nbannees = n;
cal = new GregorianCalendar();
semaines = new ArrayList();
}
}
class DebuteALaFinDe extends Contrainte
implements Serializable
{
public DebuteALaFinDe(Tache t) {
super(t);
}
public DebuteALaFinDe(Tache t, int d) {
super(t, d);
}
public int debut() {
return laTache.fin() + delai;
}
public String description() {
String descr = "fin de " + laTache.code();
if (delai < 0) descr += delai;
if (delai > 0) descr += "+" + delai;
return descr;
}
}
class DebuteAuDebutDe extends Contrainte
implements Serializable
{
public DebuteAuDebutDe(Tache t) {
super(t);
}
public DebuteAuDebutDe(Tache t, int d) {
super(t, d);
}
public int debut() {
return laTache.debut() + delai;
}
public String description() {
String descr = "deb. de " + laTache.code();
if (delai < 0) descr += delai;
if (delai > 0) descr += "+" + delai;
return descr;
}
}
class Departement
implements Serializable
{
private String nom;
public Departement(String s){
nom=s;
}
public String getNom(){
return nom;
}
public void setNom(String s){
nom = s;
}
}
class Personne
implements Serializable
{
private ArrayList lesTaches;
private String nom;
private String prenom;
private Departement departement;
private String commentaire;
public Personne(String n,String p,String d){
nom = n;
prenom = p;
departement = new Departement(d);
commentaire = "";
lesTaches = new ArrayList();
}
public Personne(String n,String p,String d,String c){
nom = n;
prenom = p;
departement = new Departement(d);
commentaire = c;
lesTaches = new ArrayList();
}
public void affiche() {
ListIterator li = lesTaches.listIterator();
Tache t;
System.out.println(" 1--------10--------20--------30--------40--------50--------60");
while (li.hasNext()) {
t = (Tache)li.next();
System.out.println(t.affichage());
}
for(int i = getTaches().size(); i < 23; i++) System.out.println(" |");
}
public void setNom(String s){
nom=s;
}
public void setPrenom(String s){
prenom=s;
}
public void setDepartement(String s){
departement=new Departement(s);
}
public void setDepartement(Departement d){
departement=d;
}
public void setCommentaire(String s){
commentaire=s;
}
public void setTaches(ArrayList a){
lesTaches=a;
}
public String getNom(){
return nom;
}
public String getPrenom(){
return prenom;
}
public String getCommentaire(){
return commentaire;
}
public Departement getDepartement(){
return departement;
}
public ArrayList getTaches(){
return lesTaches;
}
}
class Tache
implements Serializable
{
private String nom;
private char code;
private int duree, debut, fin;
private List lesContraintes;
private ArrayList lesEffectifs;
public Tache(String nom, char code, int duree) {
this.nom = nom;
this.code = code;
this.duree = duree;
debut = fin = 0;
lesContraintes = new LinkedList();
lesEffectifs = new ArrayList();
}
public ArrayList lesEffectifs(){
return lesEffectifs;
}
public char code() {
return code;
}
public void code(char c) {
code = c;
}
public String nom() {
return nom;
}
public void nom(String nm) {
nom = nm;
}
public int duree() {
return duree;
}
public void duree(int d) {
duree = d;
}
public int debut() {
return debut;
}
private void debut(int date) {
if (date > debut) debut = date;
}
public int fin() {
return fin;
}
public void fin(int date) {
fin = date;
}
public void effaceDates() {
debut = fin = 0;
}
public boolean estCalculee() {
return fin != 0;
}
public int effort(){
return lesEffectifs.size()*duree;
}
public String toString() {
String txt = "";
txt += code + "; ";
txt += nom + "; ";
txt += duree + "; ";
ListIterator li = lesContraintes.listIterator(0);
while (li.hasNext()) {
txt += ((Contrainte)li.next()).description();
if (li.hasNext()) txt += ", ";
}
return txt;
}
public String affichage() {
String txt = "";
if (nom.length() > 17) txt = nom.substring(0,17); else txt = nom;
int i;
for(i=txt.length(); i<17; i++) txt += " ";
txt += "|";
for(i=0;i<debut;i++) txt+=" ";
for(i=0;i<duree;i++) txt+=code;
return txt;
}
public boolean peutAjouterContrainte(Contrainte c){
boolean b;
ArrayList al = new ArrayList();
Contrainte a,z;
int i=0;
ListIterator li;
al.add(c);
b=(this.code()!=c.laTache().code());
while(i<al.size())
{
z= (Contrainte)al.get(i);
li = z.laTache().lesContraintes.listIterator();
while (li.hasNext()) {
a = (Contrainte)li.next();
al.add(a);
if (this.code() == a.laTache().code())
{b=false;}
}
i++;
}
return b;
}
public void ajouteContrainte(Contrainte c) {
lesContraintes.add(c);
}
public void retireContrainte(Tache t) {
ListIterator li = lesContraintes.listIterator();
Contrainte c;
while (li.hasNext()) {
c = (Contrainte)li.next();
if (c.laTache() == t) {
li.remove();
return;
}
}
}
public void affecteEffectif(Personne p){
lesEffectifs.add(p);
p.getTaches().add(this);
}
public void retireEffectif(Personne p){
lesEffectifs.remove(lesEffectifs.indexOf(p));
p.getTaches().remove(p.getTaches().indexOf(this));
}
public boolean sansContrainte() {
return lesContraintes.size() == 0;
}
public boolean toutesContraintesCalculees() {
ListIterator li = lesContraintes.listIterator();
Contrainte c;
while (li.hasNext()) {
c = (Contrainte)li.next();
if (!(c.laTache().estCalculee())) {
return false;
}
}
return true;
}
public void calculeDates() {
ListIterator li = lesContraintes.listIterator();
Contrainte c;
while (li.hasNext()) {
c = (Contrainte)li.next();
debut(c.debut());
}
fin(debut + duree);
}
public void listeEffectifs(){
Iterator it=lesEffectifs().iterator();
Personne p;
while (it.hasNext()){
p=(Personne)it.next();
System.out.println(p.getNom()+" "+p.getPrenom()+" "+p.getDepartement().getNom()+" "+p.getCommentaire());
}
}
}
class Projet
implements Serializable
{
private int nbTaches;
private List lesTaches;
private ArrayList lesEffectifs;
public Projet() {
nbTaches = 0;
lesTaches = new LinkedList();
lesEffectifs = new ArrayList();
}
public int nbTaches() {
return nbTaches;
}
public ArrayList lesEffectifs() {
return lesEffectifs;
}
public boolean estVide() {
return nbTaches == 0;
}
public void ajoute(Tache t) {
lesTaches.add(t);
nbTaches++;
}
public void affiche(boolean gantt) {
ListIterator li = lesTaches.listIterator();
Tache t;
if (gantt) {
System.out.println(" 1--------10--------20--------30--------40--------50--------60");
while (li.hasNext()) {
t = (Tache)li.next();
System.out.println(t.affichage());
}
for(int i = nbTaches; i < 23; i++) System.out.println(" |");
} else {
System.out.println("Liste des taches du projet");
while (li.hasNext()) {
t = (Tache)li.next();
System.out.println(t);
}
for(int i = nbTaches; i < 23; i++) System.out.println();
}
}
public Tache tacheDeCode(char code) {
ListIterator li = lesTaches.listIterator();
Tache t;
while (li.hasNext()) {
t = (Tache)li.next();
if (t.code() == code) return t;
}
return null;
}
public boolean uneNonCalculee() {
ListIterator li = lesTaches.listIterator();
Tache t;
while (li.hasNext()) {
t = (Tache)li.next();
if (!(t.estCalculee())) {
return true;
}
}
return false;
}
private void effaceCalculs() {
ListIterator li = lesTaches.listIterator();
Tache t;
while (li.hasNext()) {
t = (Tache)li.next();
t.effaceDates();
}
}
public void calculeDates() {
Tache t;
effaceCalculs();
do {
ListIterator li = lesTaches.listIterator();
while (li.hasNext()) {
t = (Tache)li.next();
if (!t.estCalculee())
if (t.toutesContraintesCalculees())
t.calculeDates();
}
li = null;
} while (uneNonCalculee());
}
public void ajouteEffectif(Personne p){
lesEffectifs.add(p);
}
public void retireEffectif(Personne p){
Tache t;
Personne p2;
Iterator it1=lesTaches.iterator(),it2;
while (it1.hasNext()){
t=(Tache)it1.next();
it2=t.lesEffectifs().iterator();
while (it2.hasNext()){
p2=(Personne)it2.next();
if (p==p2)
t.lesEffectifs().remove(p2);
}
}
lesEffectifs.remove(lesEffectifs.indexOf(p));
}
public int effort(){
int i=0;
Tache t;
Iterator it = lesTaches.iterator();
while (it.hasNext()){
t=(Tache)it.next();
i=i+t.effort();
}
return i;
}
public Personne personneDeNomPrenom(String n,String p){
Iterator it = lesEffectifs.iterator();
Personne e;
while (it.hasNext())
{
e=(Personne)it.next();
if ((e.getNom().toUpperCase().equals(n.toUpperCase())) && (e.getPrenom().toUpperCase().equals(p.toUpperCase())))
return e;
}
return null;
}
public void affichageEffectifs(){
Personne p;
Iterator it=lesEffectifs.iterator();
while (it.hasNext()){
p=(Personne)it.next();
System.out.println(p.getNom()+" "+p.getPrenom()+" "+p.getDepartement().getNom()+" "+p.getCommentaire());
}
}
}
class GestProj {
private static Projet leProjet;
private static Tache selection;
private static Personne selectionR;
public static void menu() {
if (selection != null) {
System.out.print("O)uvr. A)jout S)elect.[" + selection.code() + "] +)contr. ");
if (!selection.sansContrainte()) System.out.print("-)contr. ");
System.out.print("C)ode N)om D)uree efforT) E)nreg. R)essources L)iste Q)uitte ");
} else {
System.out.print("O)uvr. A)jout R)essources ");
if (!leProjet.estVide()) System.out.print("S)elect. E)nreg. ");
System.out.print("Q)uitte ");
}
}
public static void main(String arg[]) {
char choix = '*',choixR = '*',choixE='*',z;
boolean gantt = true,b,test;
char code;
String nom,prenom,departement,commentaire;
int duree;
Tache t;
leProjet = new Projet();
selection = null;
selectionR = null;
do {
b=false;
leProjet.affiche(gantt);
gantt = true;
menu();
choix = IN.getChar();
switch (choix) {
case 'l':
case 'L':
selection.listeEffectifs();
break;
case 'o':
case 'O':
System.out.print("Nom du projet a charger ? ");
nom = IN.getString();
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(nom+".prj"));
leProjet = (Projet) ois.readObject();
ois.close();
} catch(Exception e) {
System.err.println(e);
leProjet = null;
}
break;
case 'a':
case 'A':
System.out.print("Code ? ");
code = IN.getChar();
System.out.print("Nom ? ");
nom = IN.getString();
System.out.print("Duree ? ");
duree = IN.getInt();
leProjet.ajoute(selection = new Tache(nom, code, duree));
break;
case 's':
case 'S':
System.out.print("Code ? ");
code = IN.getChar();
selection = leProjet.tacheDeCode(code);
break;
case 'c':
case 'C':
System.out.print("Code de [" + selection.code() + "] ? ");
code = IN.getChar();
selection.code(code);
break;
case 'n':
case 'N':
System.out.print("Nom de [" + selection.code() + "] ? ");
nom = IN.getString();
selection.nom(nom);
break;
case 'd':
case 'D':
System.out.print("Duree de [" + selection.code() + "] ? ");
duree = IN.getInt();
selection.duree(duree);
leProjet.calculeDates();
break;
case 'r':
case 'R':
do{
if (selectionR == null){
System.out.print("Voulez-vous A)jouter ");
if (leProjet.lesEffectifs().size()!=0)
System.out.print("S)electionner ");
System.out.print("une personne ? R)etour ");
}
else
System.out.print("Voulez-vous A)jouter une personne, S)elect.[" + selectionR.getNom() + "] E)nlever, M)odifier");
if (selection!=null)
System.out.print(" D)es/aF)fecter");
System.out.print(" cette personne ? G)antt L)iste R)etour ");
choixR = IN.getChar();
switch (choixR){
case 'a':
case 'A':
System.out.print("Nom ? ");
nom = IN.getString();
System.out.print("Prenom ? ");
prenom = IN.getString();
System.out.print("Departement (IC1/IC2/Info1/Info2/RT1/RT2/Ens) ? ");
departement = IN.getString();
System.out.print("Commentaire ? ");
commentaire = IN.getString();
if (commentaire=="")
selectionR = new Personne(nom, prenom, departement);
else
selectionR = new Personne(nom, prenom, departement, commentaire);
leProjet.ajouteEffectif(selectionR);
break;
case 'd':
case 'D':
System.out.print("Voulez vous reellement desaffecter " + selectionR.getNom() + " " + selectionR.getPrenom()+ " de la tache " + selection.nom() + " (oui pour valider) ");
if (IN.getString().equals("oui"))
selection.retireEffectif(selectionR);
break;
case 'e':
case 'E':
System.out.println("Etes vous sur de vouloir supprimer "+selectionR.getNom()+" "+selectionR.getPrenom()+"? (oui pour continuer)");
if (IN.getString().equals("oui"))
leProjet.retireEffectif(selectionR);
if (leProjet.lesEffectifs().size()>0)
selectionR=(Personne)leProjet.lesEffectifs().get(0);
else selectionR=null;
break;
case 'f':
case 'F':
System.out.print("Voulez vous reellement affecter " + selectionR.getNom() + " " + selectionR.getPrenom()+ " a la tache " + selection.nom() + " (oui pour valider) ");
if (IN.getString().equals("oui"))
selection.affecteEffectif(selectionR);
break;
case 'g':
case 'G':
selectionR.affiche();
break;
case 'l':
case 'L':
leProjet.affichageEffectifs();
break;
case 'm':
case 'M':
System.out.print("Nom : [" + selectionR.getNom() + "] ? ");
nom = IN.getString();
selectionR.setNom(nom);
System.out.print("Prenom : [" + selectionR.getPrenom() + "] ? ");
prenom = IN.getString();
selectionR.setPrenom(prenom);
System.out.print("Departement : [" + selectionR.getDepartement().getNom() + "] ? ");
departement = IN.getString();
selectionR.setDepartement(departement);
if (selectionR.getCommentaire()!=null)
System.out.print("Commentaire : [" + selectionR.getCommentaire() + "] ? ");
commentaire = IN.getString();
selectionR.setCommentaire(commentaire);
//Ajout de commentaire
break;
case 's':
case 'S':
System.out.println("Entrez le nom de la personne.");
nom=IN.getString();
System.out.println("Entrez le prenom de la personne.");
prenom=IN.getString();
if (leProjet.personneDeNomPrenom(nom,prenom)!=null)
selectionR=leProjet.personneDeNomPrenom(nom,prenom);
else System.out.println("Cette personne n'a pas encore ete definie.");
break;
}
} while (choixR != 'r' && choixR != 'R');
break;
case 't':
case 'T':
System.out.println("Voulez vous calculez l'effort du P)rojet ou de la T)ache[" + selection.code() + "] ?");
choixE=IN.getChar();
if ((choixE == 't')||(choixE=='T'))
System.out.println("L'effort de la tache " + selection.code() + " est de " + selection.effort() + " H.S");
if ((choixE == 'p')||(choixE=='P'))
System.out.println("L'effort du projet est de " + leProjet.effort() + " H.S");
break;
case '+':
while(!b){
test=true;
System.out.print(selection.code()+" debute a la F)in ou au D)ebut de son predecesseur ? ");
choix = IN.getChar();
System.out.print("Code du predecesseur pour [" + selection + "] ? ");
code = IN.getChar();
t = leProjet.tacheDeCode(code);
if (t != null) {
Contrainte c;
z=' ';
if (choix == 'd' || choix == 'D') c = new DebuteAuDebutDe(t);
else c = new DebuteALaFinDe(t);
System.out.print("Delai ? ");
duree = IN.getInt();
c.delai(duree);
b=selection.peutAjouterContrainte(c);
if (b==true){
selection.ajouteContrainte(c);
}
else {
System.out.println("Vous ne pouvez pas ajouter cette contrainte.");
System.out.println("La tache de la contrainte etant un predecesseur de la tache courante.");
System.out.println("Voulez vous saisir une autre contrainte a cette tache? O)ui N)on");
while(test){
z=IN.getChar();
test = (z!='N');
if (test){
test = (z!='O');
if (test){
test = (z!='n');
if (test){
test = (z!='o');
}
}
}
}
if ((z=='n')||(z=='N'))
{b=true;}
}
}
}
leProjet.calculeDates();
break;
case '-':
System.out.print("Code de la tache a retirer des contraintes de [" + selection + "] ? ");
code = IN.getChar();
t = leProjet.tacheDeCode(code);
if (t != null) {
selection.retireContrainte(t);
leProjet.calculeDates();
}
break;
case 'e':
case 'E':
System.out.print("Nom du projet a enregistrer ? ");
nom = IN.getString();
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(nom+".prj"));
oos.writeObject(leProjet);
oos.close();
} catch(IOException e) {
System.err.println(e);
}
break;
}
} while (choix != 'q' && choix != 'Q');
}
} |
Partager