Commit 49443da5740efe7c7d66dc042292f4e1e87dee4b
1 parent
fed1c83c
tp avance
Showing
69 changed files
with
1461 additions
and
0 deletions
Show diff stats
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
... | ... | @@ -0,0 +1,113 @@ |
1 | +import java.util.*; | |
2 | + | |
3 | +public class Banque { | |
4 | + List<Compte> comptes; | |
5 | + int nbComptes =0; | |
6 | + | |
7 | + public Banque(){ | |
8 | + comptes = new ArrayList<Compte>(); | |
9 | + this.nbComptes = 0 ; | |
10 | + } | |
11 | + | |
12 | + public int ouvrirCompte(){ | |
13 | + comptes.add(new Compte()); | |
14 | + nbComptes ++; | |
15 | + return this.nbComptes; | |
16 | + } | |
17 | + | |
18 | + public int ouvrirCompteEpargne(double credit, double interet){ | |
19 | + comptes.add(new CompteEpargne(credit,interet)); | |
20 | + nbComptes ++; | |
21 | + return nbComptes; | |
22 | + } | |
23 | + | |
24 | + public Compte getCompte(int i) throws CompteInexistantException{ | |
25 | + if(i > nbComptes && i>0){ | |
26 | + throw new CompteInexistantException(); | |
27 | + | |
28 | + }else{ | |
29 | + return this.comptes.get(i-1); | |
30 | + } | |
31 | + } | |
32 | + | |
33 | + public void crediter(int i, double x)throws CompteInexistantException{ | |
34 | + if(i > nbComptes && i>0){ | |
35 | + throw new CompteInexistantException(); | |
36 | + }else{ | |
37 | + getCompte(i).crediter(x); | |
38 | + } | |
39 | + } | |
40 | + | |
41 | + public void debiter(int i, double x)throws CompteInexistantException{ | |
42 | + if(i > nbComptes && i>0){ | |
43 | + throw new CompteInexistantException(); | |
44 | + }else{ | |
45 | + getCompte(i).debiter(x); | |
46 | + } | |
47 | + } | |
48 | + | |
49 | + public double totalSolde(){ | |
50 | + double totalSolde = 0; | |
51 | + if(!comptes.isEmpty()){ | |
52 | + for(Compte compte : comptes){ | |
53 | + totalSolde += compte.solde(); | |
54 | + }} | |
55 | + return totalSolde; | |
56 | + } | |
57 | + | |
58 | + public String etat(int i) throws CompteInexistantException{ | |
59 | + if(i > nbComptes){ | |
60 | + throw new CompteInexistantException(); | |
61 | + }else{ | |
62 | + return getCompte(i).toString(); | |
63 | + } | |
64 | + } | |
65 | + | |
66 | + public void etat() { | |
67 | + System.out.println("Vos comptes: "); | |
68 | + int indice=0; | |
69 | + for(Compte compte : comptes){ | |
70 | + indice++; | |
71 | + System.out.println("Pour le compte: " + indice + " et "+ compte.toString()); | |
72 | + } | |
73 | + } | |
74 | + | |
75 | + public void virement(int numSrc, int numDest, double x)throws CompteInexistantException{ | |
76 | + if((numSrc > nbComptes)||(numDest > nbComptes)){ | |
77 | + throw new CompteInexistantException(); | |
78 | + }else{ | |
79 | + getCompte(numSrc).virerVers(x, getCompte(numDest)); | |
80 | + } | |
81 | + } | |
82 | + | |
83 | + public double interets(int i)throws CompteInexistantException{ | |
84 | + if(i > nbComptes){ | |
85 | + throw new CompteInexistantException(); | |
86 | + }else{ | |
87 | + try{ | |
88 | + CompteEpargne ce = (CompteEpargne)getCompte(i); | |
89 | + return ce.interets(); | |
90 | + } catch (ClassCastException e){ | |
91 | + | |
92 | + } | |
93 | + | |
94 | + | |
95 | + } | |
96 | + return 0; | |
97 | + | |
98 | + } | |
99 | + | |
100 | + public void echeance(int i)throws CompteInexistantException{ | |
101 | + if(i > nbComptes){ | |
102 | + throw new CompteInexistantException(); | |
103 | + }else{ | |
104 | + try{ | |
105 | + CompteEpargne ce = (CompteEpargne)getCompte(i); | |
106 | + ce.echeance(); | |
107 | + } catch (ClassCastException e){ | |
108 | + } | |
109 | + } | |
110 | + } | |
111 | + | |
112 | + | |
113 | +} | ... | ... |
No preview for this file type
... | ... | @@ -0,0 +1,52 @@ |
1 | + | |
2 | + | |
3 | +public class Compte { | |
4 | + double credit = 0; | |
5 | + double debit = 0; | |
6 | + | |
7 | + public double getCredit(){ | |
8 | + return this.credit; | |
9 | + } | |
10 | + | |
11 | + public double getDebit(){ | |
12 | + return this.debit; | |
13 | + } | |
14 | + | |
15 | + public void setCredit(double x){ | |
16 | + this.credit = x; | |
17 | + } | |
18 | + | |
19 | + public void setDebit(double x){ | |
20 | + this.debit = x; | |
21 | + } | |
22 | + | |
23 | + public Compte(){ | |
24 | + | |
25 | + } | |
26 | + | |
27 | + public Compte(double val){ | |
28 | + setCredit(val); | |
29 | + } | |
30 | + | |
31 | + public void crediter(double val){ | |
32 | + setCredit(getCredit()+val); | |
33 | + } | |
34 | + | |
35 | + public void debiter(double val){ | |
36 | + setDebit(getDebit()+val); | |
37 | + } | |
38 | + | |
39 | + public double solde(){ | |
40 | + return (getCredit()-getDebit()); | |
41 | + } | |
42 | + | |
43 | + public String toString(){ | |
44 | + return "Le solde actuel est de "+solde()+" ("+getCredit()+" - "+getDebit()+")"; | |
45 | + } | |
46 | + | |
47 | + public void virerVers (double x, Compte dest){ | |
48 | + dest.crediter(x); | |
49 | + this.debiter(x); | |
50 | + } | |
51 | + | |
52 | +} | ... | ... |
No preview for this file type
... | ... | @@ -0,0 +1,49 @@ |
1 | + | |
2 | +public class CompteEpargne extends Compte { | |
3 | + | |
4 | + private double interet; | |
5 | + | |
6 | + public double getInteret(){ | |
7 | + return this.interet; | |
8 | + } | |
9 | + | |
10 | + public void setInteret(double x){ | |
11 | + this.interet = x; | |
12 | + } | |
13 | + | |
14 | + public double interets(){ | |
15 | + return (getCredit()-getDebit())*getInteret(); | |
16 | + } | |
17 | + | |
18 | + public void echeance(){ | |
19 | + crediter(interets()); | |
20 | + } | |
21 | + | |
22 | + public void debiter(double val){ | |
23 | + if((getCredit()-val)>0){ | |
24 | + setDebit(getDebit()+val); | |
25 | + | |
26 | + }else { | |
27 | + System.out.println("Compte non débitable"); | |
28 | + } | |
29 | + } | |
30 | + | |
31 | + public CompteEpargne(double creditInit, double interet){ | |
32 | + super(creditInit); | |
33 | + setInteret(interet); | |
34 | + } | |
35 | + | |
36 | + public CompteEpargne(){ | |
37 | + super(); | |
38 | + setInteret(0.1); | |
39 | + } | |
40 | + | |
41 | + public String etat(){ | |
42 | + return super.toString()+" Interets du mois: "+ interets(); | |
43 | + } | |
44 | + | |
45 | + public String toString(){ | |
46 | + return super.toString()+" Interets du mois: "+ interets(); | |
47 | + } | |
48 | + | |
49 | +} | ... | ... |
No preview for this file type
No preview for this file type
No preview for this file type
... | ... | @@ -0,0 +1,136 @@ |
1 | +import java.util.Scanner; | |
2 | + | |
3 | +public class Guichet { | |
4 | + static Scanner in = new Scanner(System.in); | |
5 | + // creation de la banque : | |
6 | + static Banque bank = new Banque(); | |
7 | + static int nombreEssai ; | |
8 | + | |
9 | + public static void main (String[] args) { | |
10 | + nombreEssai=0; | |
11 | + int choix=0; | |
12 | + do { | |
13 | + menu(); | |
14 | + System.out.print("votre choix? "); | |
15 | + choix = in.nextInt(); | |
16 | + switch (choix) { | |
17 | + case 1 : // etat des comptes | |
18 | + bank.etat(); | |
19 | + break; | |
20 | + case 2 : // creer un nouveau compte | |
21 | + menuNouveauCompte(); | |
22 | + break; | |
23 | + case 3: // crediter un compte | |
24 | + menuCrediter(); | |
25 | + break; | |
26 | + case 4: // debiter un compte | |
27 | + menuDebiter(); | |
28 | + break; | |
29 | + case 5: // effectuer un virement | |
30 | + menuVirement(); | |
31 | + break; | |
32 | + case 6: // effectuer un virement | |
33 | + menuNouveauCompteEpargne(); | |
34 | + break; | |
35 | + case 7: | |
36 | + menuInterets(); | |
37 | + break; | |
38 | + case 8: // effectuer un virement | |
39 | + menuEcheance(); | |
40 | + break; | |
41 | + case 0: // quitter | |
42 | + } | |
43 | + } while (choix!=0); | |
44 | + System.out.println("au revoir"); | |
45 | + } | |
46 | + | |
47 | + static void menu() { | |
48 | + System.out.println("\n1: etat des comptes\n2: creer un nouveau compte\n3: crediter un compte\n4: debiter un compte\n5: effectuer un virement\n6: creer un nouveau compte epargne\n7: interets\n8: echeance\n0: quitter"); | |
49 | + } | |
50 | + | |
51 | + static void menuNouveauCompte() { | |
52 | + int num; | |
53 | + num=bank.ouvrirCompte(); | |
54 | + System.out.println("numero= "+num); | |
55 | + } | |
56 | + | |
57 | + static void menuNouveauCompteEpargne() { | |
58 | + double num; | |
59 | + System.out.print("\ncredit? "); | |
60 | + num=in.nextDouble(); | |
61 | + System.out.print("interet? "); | |
62 | + num=bank.ouvrirCompteEpargne(num, in.nextDouble()); | |
63 | + System.out.println("numero= "+num); | |
64 | + } | |
65 | + | |
66 | + static void menuCrediter(){ | |
67 | +try{ | |
68 | + int num; | |
69 | + System.out.print("\nnumero du compte? "); | |
70 | + num=in.nextInt(); | |
71 | + System.out.print("somme? "); | |
72 | + bank.crediter(num, in.nextDouble()); | |
73 | +}catch (CompteInexistantException e){ | |
74 | +nombreEssai++; | |
75 | +System.out.println("Nombre essais invalides: "+ nombreEssai); | |
76 | +} | |
77 | + | |
78 | + } | |
79 | + | |
80 | + static void menuDebiter() { | |
81 | + try{ | |
82 | + int num; | |
83 | + System.out.print("\nnumero du compte? "); | |
84 | + num=in.nextInt(); | |
85 | + System.out.print("somme? "); | |
86 | + bank.debiter(num, in.nextDouble()); | |
87 | + }catch (CompteInexistantException e){ | |
88 | + nombreEssai++; | |
89 | +System.out.println("Nombre essais invalides: "+ nombreEssai); | |
90 | +} | |
91 | + | |
92 | + } | |
93 | + | |
94 | + static void menuVirement() { | |
95 | + try{ | |
96 | + int from, to; | |
97 | + System.out.print("\ncompte a debiter? "); | |
98 | + from=in.nextInt(); | |
99 | + System.out.print("compte a crediter? "); | |
100 | + to=in.nextInt(); | |
101 | + System.out.print("somme? "); | |
102 | + bank.virement(from, to, in.nextDouble()); | |
103 | + }catch (CompteInexistantException e){ | |
104 | + nombreEssai++; | |
105 | +System.out.println("Nombre essais invalides: "+ nombreEssai); | |
106 | +} | |
107 | + | |
108 | + } | |
109 | + | |
110 | + static void menuEcheance() { | |
111 | + try{ | |
112 | + int num; | |
113 | + System.out.print("\nnumero du compte? "); | |
114 | + num=in.nextInt(); | |
115 | + | |
116 | + bank.echeance(num); | |
117 | + }catch (CompteInexistantException e){ | |
118 | + nombreEssai++; | |
119 | +System.out.println("Nombre essais invalides: "+ nombreEssai); | |
120 | +} | |
121 | + | |
122 | + } | |
123 | + | |
124 | + static void menuInterets() { | |
125 | + try{ | |
126 | + int num; | |
127 | + System.out.print("\nnumero du compte? "); | |
128 | + num=in.nextInt(); | |
129 | + bank.interets(num); | |
130 | + }catch (CompteInexistantException e){ | |
131 | + nombreEssai++; | |
132 | +System.out.println("Nombre essais invalides: "+ nombreEssai); | |
133 | +} | |
134 | + | |
135 | + } | |
136 | +} | ... | ... |
No preview for this file type
... | ... | @@ -0,0 +1,32 @@ |
1 | +import java.util.*; | |
2 | + | |
3 | +public class Banque { | |
4 | + List<Compte> comptes; | |
5 | + int nbComptes ; | |
6 | + public Banque(){ | |
7 | + | |
8 | + } | |
9 | + public int ouvrirCompte(){ | |
10 | + } | |
11 | + | |
12 | + public Compte getCompte(int i) { | |
13 | + } | |
14 | + | |
15 | + public void crediter(int i, double x){ | |
16 | + } | |
17 | + | |
18 | + public void debiter(int i, double x){ | |
19 | + } | |
20 | + | |
21 | + public double totalSolde(){ | |
22 | + } | |
23 | + | |
24 | + public String etat(int i){ | |
25 | + } | |
26 | + | |
27 | + public void etat() { | |
28 | + } | |
29 | + | |
30 | + public void virement(int numSrc, int numDest, double x){ | |
31 | + } | |
32 | +} | |
0 | 33 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,71 @@ |
1 | +import java.util.Scanner; | |
2 | + | |
3 | +public class Guichet { | |
4 | + static Scanner in = new Scanner(System.in); | |
5 | + // creation de la banque : | |
6 | + static Banque bank = new Banque(); | |
7 | + | |
8 | + public static void main (String[] args) { | |
9 | + int choix=0; | |
10 | + do { | |
11 | + menu(); | |
12 | + System.out.print("votre choix? "); | |
13 | + choix = in.nextInt(); | |
14 | + switch (choix) { | |
15 | + case 1 : // etat des comptes | |
16 | + bank.etat(); | |
17 | + break; | |
18 | + case 2 : // creer un nouveau compte | |
19 | + menuNouveauCompte(); | |
20 | + break; | |
21 | + case 3: // crediter un compte | |
22 | + menuCrediter(); | |
23 | + break; | |
24 | + case 4: // debiter un compte | |
25 | + menuDebiter(); | |
26 | + break; | |
27 | + case 5: // effectuer un virement | |
28 | + menuVirement(); | |
29 | + break; | |
30 | + case 0: // quitter | |
31 | + } | |
32 | + } while (choix!=0); | |
33 | + System.out.println("au revoir"); | |
34 | + } | |
35 | + | |
36 | + static void menu() { | |
37 | + System.out.println("\n1: etat des comptes\n2: creer un nouveau compte\n3: crediter un compte\n4: debiter un compte\n5: effectuer un virement\n0: quitter"); | |
38 | + } | |
39 | + | |
40 | + static void menuNouveauCompte() { | |
41 | + int num; | |
42 | + num=bank.ouvrirCompte(); | |
43 | + System.out.println("numero= "+num); | |
44 | + } | |
45 | + | |
46 | + static void menuCrediter() { | |
47 | + int num; | |
48 | + System.out.print("\nnumero du compte? "); | |
49 | + num=in.nextInt(); | |
50 | + System.out.print("somme? "); | |
51 | + bank.crediter(num, in.nextDouble()); | |
52 | + } | |
53 | + | |
54 | + static void menuDebiter() { | |
55 | + int num; | |
56 | + System.out.print("\nnumero du compte? "); | |
57 | + num=in.nextInt(); | |
58 | + System.out.print("somme? "); | |
59 | + bank.debiter(num, in.nextDouble()); | |
60 | + } | |
61 | + | |
62 | + static void menuVirement() { | |
63 | + int from, to; | |
64 | + System.out.print("\ncompte a debiter? "); | |
65 | + from=in.nextInt(); | |
66 | + System.out.print("compte a crediter? "); | |
67 | + to=in.nextInt(); | |
68 | + System.out.print("somme? "); | |
69 | + bank.virement(from, to, in.nextDouble()); | |
70 | + } | |
71 | +} | |
0 | 72 | \ No newline at end of file | ... | ... |
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
... | ... | @@ -0,0 +1,84 @@ |
1 | +import java.util.Scanner; | |
2 | + | |
3 | +public class Application { | |
4 | + | |
5 | + static Scanner in = new Scanner(System.in); | |
6 | + public static void main(String[] argv) { | |
7 | + | |
8 | + Bibliotheque bib = new Bibliotheque(); | |
9 | + | |
10 | + //Ranger des ouvrages: | |
11 | + bib.add("I101",new Ouvrage("C","Kernighan")); | |
12 | + bib.add("L202",new Ouvrage("Germinal","Zola")); | |
13 | + bib.add("S303",new Ouvrage("Parapente","Ali Gali")); | |
14 | + bib.add("I345",new Ouvrage("Java","Eckel")); | |
15 | + bib.add("1",new Ouvrage("Test","E")); | |
16 | + bib.add("2",new Revue("Date","Eckel",20180000,1)); | |
17 | + bib.add("3",new Revue("PasDate","Teckel",20180514,1)); | |
18 | + bib.listing(); | |
19 | + | |
20 | + int choix=0; | |
21 | + do { | |
22 | + menu(); | |
23 | + System.out.print("votre choix? "); | |
24 | + choix = in.nextInt(); | |
25 | + switch (choix) { | |
26 | + case 1 : //emprunt | |
27 | + menuEmprunt(bib); | |
28 | + menuListing(bib); | |
29 | + break; | |
30 | + case 2 : //retour | |
31 | + menuRetourner(bib); | |
32 | + menuListing(bib); | |
33 | + break; | |
34 | + | |
35 | + case 3 : //affiche | |
36 | + menuListing(bib); | |
37 | + break; | |
38 | + case 0: // quitter | |
39 | + } | |
40 | + } while (choix!=0); | |
41 | + //Permettre a l'utilisateur d'emprunter/retourner un ouvrage | |
42 | + //en demandant son code. | |
43 | + //Transformer les exceptions en message d'erreur. | |
44 | + | |
45 | + | |
46 | + | |
47 | + | |
48 | + } | |
49 | + | |
50 | + static void menu() { | |
51 | + System.out.println("\n1: Emprunter\n2: Retourner\n3: Lister\n0: quitter"); | |
52 | + } | |
53 | + | |
54 | +static void menuEmprunt(Bibliotheque bib ) { | |
55 | + try{ | |
56 | + System.out.print("\ncode? "); | |
57 | + String code= in.next(); | |
58 | + | |
59 | + bib.emprunter(code); | |
60 | + | |
61 | + }catch (Exception e){ | |
62 | + e.printStackTrace(); | |
63 | + } | |
64 | + | |
65 | + } | |
66 | + | |
67 | + static void menuRetourner(Bibliotheque bib ) { | |
68 | + try{ | |
69 | + | |
70 | + System.out.print("\ncode? "); | |
71 | + String code=in.next(); | |
72 | + | |
73 | + bib.retourner(code); | |
74 | + }catch (OuvrageInconnuException e){ | |
75 | + e.printStackTrace(); | |
76 | + } | |
77 | + | |
78 | + } | |
79 | + | |
80 | + static void menuListing(Bibliotheque bib ) { | |
81 | + bib.listing(); | |
82 | + } | |
83 | + | |
84 | +} | ... | ... |
No preview for this file type
No preview for this file type
... | ... | @@ -0,0 +1,68 @@ |
1 | +import java.util.*; | |
2 | + | |
3 | +public class Bibliotheque { | |
4 | + | |
5 | +//variables d'instances | |
6 | + protected Map<String,Ouvrage> ouvrages = new TreeMap<String,Ouvrage>(); | |
7 | + static final int date = 20180518; | |
8 | + | |
9 | +//methodes a programmer | |
10 | + public void add(String code, Ouvrage o){ | |
11 | + ouvrages.put(code,o); | |
12 | + | |
13 | + } | |
14 | + | |
15 | + | |
16 | + public int totalEmprunts(){ | |
17 | + int total = 0; | |
18 | + | |
19 | + for (Map.Entry<String, Ouvrage> o: ouvrages.entrySet()) { | |
20 | + Ouvrage ouvrage = o.getValue(); | |
21 | + total += ouvrage.compteur; | |
22 | + } | |
23 | + | |
24 | + return total; | |
25 | + | |
26 | + } | |
27 | + | |
28 | + public void listing(){ | |
29 | + for (Map.Entry<String, Ouvrage> o: ouvrages.entrySet()) { | |
30 | + Ouvrage ouvrage = o.getValue(); | |
31 | + System.out.println(""+ ouvrage.toString()); | |
32 | + } | |
33 | + } | |
34 | + | |
35 | + public void emprunter(String code)throws OuvrageInconnuException,NonDisponibleException,NonDispoException{ | |
36 | + try { | |
37 | + Revue revue = (Revue) ouvrages.get(code); | |
38 | + if(revue == null){ | |
39 | + throw new OuvrageInconnuException(); | |
40 | + } | |
41 | + revue.emprunter(date); | |
42 | + }catch(ClassCastException e){ | |
43 | + //e.printStackTrace(); | |
44 | + Ouvrage ouvrage = ouvrages.get(code); | |
45 | + if(ouvrage == null){ | |
46 | + throw new OuvrageInconnuException(); | |
47 | + } | |
48 | + ouvrage.emprunter(); | |
49 | + } | |
50 | + | |
51 | + | |
52 | + } | |
53 | + | |
54 | + public void retourner(String code)throws OuvrageInconnuException{ | |
55 | + Ouvrage ouvrage = ouvrages.get(code); | |
56 | + if(ouvrage == null){ | |
57 | + throw new OuvrageInconnuException(); | |
58 | + } | |
59 | + ouvrage.retourner(); | |
60 | + | |
61 | + } | |
62 | + | |
63 | + public TreeMap<String,Ouvrage> getOuvrage(){ | |
64 | + Arrays.sort(ouvrages, new ComparateurOuvrage()); | |
65 | + } | |
66 | + | |
67 | + | |
68 | +} | ... | ... |
No preview for this file type
No preview for this file type
No preview for this file type
... | ... | @@ -0,0 +1,42 @@ |
1 | +public class Ouvrage implements Comparable<Ouvrage>{ | |
2 | +//variables d'instance | |
3 | + protected String titre, auteur; | |
4 | + protected boolean emprunte; | |
5 | + protected int compteur; // nombre d'emprunts | |
6 | + | |
7 | +//methodes et constructeurs | |
8 | + public Ouvrage(String tit, String aut){ | |
9 | + this.titre = tit; | |
10 | + this.auteur = aut; | |
11 | + } | |
12 | + | |
13 | + public String toString(){ | |
14 | + return "Titre; "+titre+" Auteur; "+ auteur+" emprunter: "+ emprunte; | |
15 | + } | |
16 | + | |
17 | + public void emprunter() throws NonDisponibleException{ | |
18 | + if(this.emprunte == true){ | |
19 | + throw new NonDisponibleException(); | |
20 | + } else { | |
21 | + this.emprunte = true; | |
22 | + this.compteur ++; | |
23 | + } | |
24 | + } | |
25 | + | |
26 | + public void retourner(){ | |
27 | + this.emprunte = false; | |
28 | + } | |
29 | + | |
30 | + public int getCompteur(){ | |
31 | + return this.compteur; | |
32 | + } | |
33 | + | |
34 | + @Override | |
35 | + public int compareTo(Ouvrage ouvrage) { | |
36 | + if (this.compteur <= ouvrage.compteur) { | |
37 | + return -1; | |
38 | + } else { | |
39 | + return 1; | |
40 | + } | |
41 | + } | |
42 | +} | ... | ... |
No preview for this file type
No preview for this file type
... | ... | @@ -0,0 +1,28 @@ |
1 | +public class Revue extends Ouvrage { | |
2 | + | |
3 | + protected int dateEdit; | |
4 | + protected int num; | |
5 | + | |
6 | + public Revue(String tit, String aut, int dateEdit, int num){ | |
7 | + super(tit,aut); | |
8 | + this.dateEdit = dateEdit; | |
9 | + this.num = num; | |
10 | + | |
11 | + } | |
12 | + | |
13 | + public void emprunter(int date) throws NonDisponibleException,NonDispoException{ | |
14 | + if(this.emprunte == true){ | |
15 | + throw new NonDisponibleException(); | |
16 | + } else { | |
17 | + if(date > dateEdit +7){ | |
18 | + this.emprunte = true; | |
19 | + this.compteur ++; | |
20 | + }else{ | |
21 | + throw new NonDispoException(); | |
22 | + } | |
23 | + } | |
24 | + } | |
25 | + | |
26 | + | |
27 | + | |
28 | +} | ... | ... |
... | ... | @@ -0,0 +1,7 @@ |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<classpath> | |
3 | + <classpathentry kind="src" path="src"/> | |
4 | + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | |
5 | + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | |
6 | + <classpathentry kind="output" path="bin"/> | |
7 | +</classpath> | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +/bin/ | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<projectDescription> | |
3 | + <name>tp_Test</name> | |
4 | + <comment></comment> | |
5 | + <projects> | |
6 | + </projects> | |
7 | + <buildSpec> | |
8 | + <buildCommand> | |
9 | + <name>org.eclipse.jdt.core.javabuilder</name> | |
10 | + <arguments> | |
11 | + </arguments> | |
12 | + </buildCommand> | |
13 | + </buildSpec> | |
14 | + <natures> | |
15 | + <nature>org.eclipse.jdt.core.javanature</nature> | |
16 | + </natures> | |
17 | +</projectDescription> | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +eclipse.preferences.version=1 | |
2 | +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | |
3 | +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | |
4 | +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | |
5 | +org.eclipse.jdt.core.compiler.compliance=1.8 | |
6 | +org.eclipse.jdt.core.compiler.debug.lineNumber=generate | |
7 | +org.eclipse.jdt.core.compiler.debug.localVariable=generate | |
8 | +org.eclipse.jdt.core.compiler.debug.sourceFile=generate | |
9 | +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | |
10 | +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | |
11 | +org.eclipse.jdt.core.compiler.source=1.8 | ... | ... |
... | ... | @@ -0,0 +1,40 @@ |
1 | + | |
2 | +import java.util.*; | |
3 | + | |
4 | +import static org.junit.Assert.*; | |
5 | + | |
6 | +import org.junit.Test; | |
7 | + | |
8 | +public class ProgressionArithmetiqueTest { | |
9 | + | |
10 | + | |
11 | + @Test | |
12 | + public void testConstructeur() throws TestException { | |
13 | + ProgressionArithmetique pa = new ProgressionArithmetique(2, 1); | |
14 | + try{ | |
15 | + assertEquals (pa.termes.size(), 1); | |
16 | + } | |
17 | + catch(AssertionError e){ | |
18 | + throw new TestException("*****Le premier terme doit etre place dans la liste de termes*****"); | |
19 | + } | |
20 | + catch(NoSuchFieldError e) { | |
21 | + throw new TestException("*****La variable d'instance termes doit etre une collection, une ArrayList*****"); | |
22 | + } | |
23 | + } | |
24 | + @Test | |
25 | + public void testNext() throws TestException { | |
26 | + ProgressionArithmetique pa = new ProgressionArithmetique(2, 1); | |
27 | + try{ | |
28 | + assertEquals (pa.termes.size(), 1); | |
29 | + pa.next(); | |
30 | + assertEquals (pa.termes.size(), 2); | |
31 | + assertTrue (pa.getTerme() == 3); | |
32 | + } | |
33 | + catch(AssertionError e){ | |
34 | + throw new TestException("*****Erreur dans le calcul de next() ou de getTerme()*****"); | |
35 | + } | |
36 | + catch(NoSuchFieldError e) { | |
37 | + throw new TestException("*****La variable d'instance termes doit etre une collection, une ArrayList*****"); | |
38 | + } | |
39 | + } | |
40 | +} | ... | ... |
... | ... | @@ -0,0 +1,38 @@ |
1 | +import java.util.*; | |
2 | + | |
3 | +import static org.junit.Assert.*; | |
4 | + | |
5 | +import org.junit.Test; | |
6 | +public class ProgressionGeometriqueTest { | |
7 | + | |
8 | + | |
9 | + @Test | |
10 | + public void testConstructeur() throws TestException { | |
11 | + ProgressionGeometrique pg = new ProgressionGeometrique(2, 1); | |
12 | + try{ | |
13 | + assertEquals (pg.termes.size(), 1); | |
14 | + } | |
15 | + catch(AssertionError e){ | |
16 | + throw new TestException("*****Le premier terme doit etre place dans la liste de termes*****"); | |
17 | + } | |
18 | + catch(NoSuchFieldError e) { | |
19 | + throw new TestException("*****La variable d'instance termes doit etre une collection, une ArrayList*****"); | |
20 | + } | |
21 | + } | |
22 | + @Test | |
23 | + public void testNext() throws TestException { | |
24 | + ProgressionGeometrique pg = new ProgressionGeometrique(2, 3); | |
25 | + try{ | |
26 | + assertEquals (pg.termes.size(), 1); | |
27 | + pg.next(); | |
28 | + assertEquals (pg.termes.size(), 2); | |
29 | + assertTrue (pg.getTerme() == 6); | |
30 | + } | |
31 | + catch(AssertionError e){ | |
32 | + throw new TestException("*****Erreur dans le calcul de next() ou de getTerme()*****"); | |
33 | + } | |
34 | + catch(NoSuchFieldError e) { | |
35 | + throw new TestException("*****La variable d'instance termes doit etre une collection, une ArrayList*****"); | |
36 | + } | |
37 | + } | |
38 | +} | ... | ... |
... | ... | @@ -0,0 +1,43 @@ |
1 | + | |
2 | +import java.lang.reflect.Modifier; | |
3 | +import java.util.*; | |
4 | + | |
5 | +import static org.junit.Assert.*; | |
6 | + | |
7 | +import org.junit.Test; | |
8 | +public class ProgressionHierarchieTest { | |
9 | + @Test | |
10 | + public void testAbstractProgression() throws TestException { | |
11 | + try{ | |
12 | + assertTrue (Modifier.isAbstract(Progression.class.getModifiers())); | |
13 | + } | |
14 | + catch(AssertionError e){ | |
15 | + throw new TestException("*****La classe Progression doit etre abstraite*****"); | |
16 | + } | |
17 | + } | |
18 | + | |
19 | + @Test | |
20 | + public void testProgressionGeometrique() throws TestException { | |
21 | + try{ | |
22 | + assertTrue (ProgressionGeometrique.class.getDeclaredMethods().length==1); | |
23 | + assertTrue (ProgressionGeometrique.class.getDeclaredMethod("next").getReturnType()==void.class); | |
24 | + } | |
25 | + catch(AssertionError e){ | |
26 | + throw new TestException("*****Dans la classe ProgressionGeometrique vous ne devez redefinir que next()*****"); | |
27 | + } catch (NoSuchMethodException e) { | |
28 | + throw new TestException("*****Dans la classe ProgressionGeometrique vous ne devez redefinir que next()*****"); | |
29 | + } | |
30 | + } | |
31 | + @Test | |
32 | + public void testProgressionArithmetique() throws TestException { | |
33 | + try{ | |
34 | + assertTrue (ProgressionArithmetique.class.getDeclaredMethods().length==1); | |
35 | + assertTrue (ProgressionArithmetique.class.getDeclaredMethod("next").getReturnType()==void.class); | |
36 | + } | |
37 | + catch(AssertionError e){ | |
38 | + throw new TestException("*****Dans la classe ProgressionArithmetique vous ne devez redefinir que next()*****"); | |
39 | + } catch (NoSuchMethodException e) { | |
40 | + throw new TestException("*****Dans la classe ProgressionArithmetique vous ne devez redefinir que next()*****"); | |
41 | + } | |
42 | + } | |
43 | +} | ... | ... |
... | ... | @@ -0,0 +1,62 @@ |
1 | +import java.util.*; | |
2 | + | |
3 | +public class ProgressionArithmetique { | |
4 | + | |
5 | + ArrayList<Double> termes; | |
6 | + double raison; | |
7 | + int rang; | |
8 | + | |
9 | + public ProgressionArithmetique(double terme1, double raison) { | |
10 | + termes = new ArrayList<Double>(); | |
11 | + termes.add(terme1); | |
12 | + this.setRang(0); | |
13 | + this.setRaison(raison); | |
14 | + } | |
15 | + | |
16 | + public int getRang() { | |
17 | + return this.rang; | |
18 | + } | |
19 | + | |
20 | + public void setRang(int rang) { | |
21 | + this.rang = rang; | |
22 | + } | |
23 | + | |
24 | + public double getRaison() { | |
25 | + return this.raison; | |
26 | + } | |
27 | + | |
28 | + public void setRaison(double raison) { | |
29 | + this.raison = raison; | |
30 | + } | |
31 | + | |
32 | + void next() { | |
33 | + double d = this.termes.get(getRang()); | |
34 | + d += raison; | |
35 | + termes.add(d); | |
36 | + rang++; | |
37 | + } | |
38 | + | |
39 | + /** | |
40 | + * Calcul les n prochaines itérations | |
41 | + */ | |
42 | + void next(int n) { | |
43 | + for (int i = 0; i < n; i++) { | |
44 | + next(); | |
45 | + } | |
46 | + } | |
47 | + | |
48 | + /** | |
49 | + * Récupère le dernier terme | |
50 | + */ | |
51 | + public double getTerme() { | |
52 | + return termes.get(getRang()); | |
53 | + } | |
54 | + | |
55 | + public String toString() { | |
56 | + String res = "progression:"; | |
57 | + for (Double d : termes) { | |
58 | + res += " " + d; | |
59 | + } | |
60 | + return res; | |
61 | + } | |
62 | +} | ... | ... |
... | ... | @@ -0,0 +1,62 @@ |
1 | +import java.util.*; | |
2 | + | |
3 | +public class ProgressionGeometrique { | |
4 | + | |
5 | + ArrayList<Double> termes; | |
6 | + double raison; | |
7 | + int rang; | |
8 | + | |
9 | + public ProgressionGeometrique(double terme1, double raison) { | |
10 | + termes = new ArrayList<Double>(); | |
11 | + termes.add(terme1); | |
12 | + this.setRang(0); | |
13 | + this.setRaison(raison); | |
14 | + } | |
15 | + | |
16 | + public int getRang() { | |
17 | + return this.rang; | |
18 | + } | |
19 | + | |
20 | + public void setRang(int rang) { | |
21 | + this.rang = rang; | |
22 | + } | |
23 | + | |
24 | + public double getRaison() { | |
25 | + return this.raison; | |
26 | + } | |
27 | + | |
28 | + public void setRaison(double raison) { | |
29 | + this.raison = raison; | |
30 | + } | |
31 | + | |
32 | + void next() { | |
33 | + double d = this.termes.get(getRang()); | |
34 | + d *= raison; | |
35 | + termes.add(d); | |
36 | + rang++; | |
37 | + } | |
38 | + | |
39 | + /** | |
40 | + * Calcul les n prochaines itérations | |
41 | + */ | |
42 | + void next(int n) { | |
43 | + for (int i = 0; i < n; i++) { | |
44 | + next(); | |
45 | + } | |
46 | + } | |
47 | + | |
48 | + /** | |
49 | + * Récupère le dernier terme | |
50 | + */ | |
51 | + public double getTerme() { | |
52 | + return termes.get(getRang()); | |
53 | + } | |
54 | + | |
55 | + public String toString() { | |
56 | + String res = "progression:"; | |
57 | + for (Double d : termes) { | |
58 | + res += " " + d; | |
59 | + } | |
60 | + return res; | |
61 | + } | |
62 | +} | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +import static org.junit.Assert.assertEquals; | |
2 | + | |
3 | +import org.junit.Test; | |
4 | + | |
5 | +public class ProgressionGeometriqueTest { | |
6 | + | |
7 | + @Test | |
8 | + public void testConstructeur() { | |
9 | + ProgressionGeometrique pg = new ProgressionGeometrique(10, 5); | |
10 | + | |
11 | + assertEquals(pg.termes.size(), 1); | |
12 | + | |
13 | + } | |
14 | + | |
15 | + @Test | |
16 | + public void testNext() { | |
17 | + ProgressionGeometrique pg = new ProgressionGeometrique(10, 5); | |
18 | + | |
19 | + assertEquals(pg.termes.size(), 1); | |
20 | + | |
21 | + pg.next(); | |
22 | + assertEquals(pg.termes.size(), 2); | |
23 | + assertEquals(pg.getTerme(), 50, 0); | |
24 | + | |
25 | + } | |
26 | +} | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +import java.util.*; | |
2 | + | |
3 | +public class TestArithmetique { | |
4 | + | |
5 | + public static void main(String[] args){ | |
6 | + Scanner sc = new Scanner(System.in); | |
7 | + System.out.print("\npremier terme? "); | |
8 | + double d = sc.nextDouble(); | |
9 | + System.out.print("\nraison? "); | |
10 | + double raison = sc.nextDouble(); | |
11 | + ProgressionArithmetique pa = new ProgressionArithmetique(d,raison); | |
12 | + | |
13 | + System.out.print("\nnext (y/n)? "); | |
14 | + char next = sc.next().charAt(0); | |
15 | + while(next == 'y'){ | |
16 | + pa.next(); | |
17 | + System.out.println("\n-> "+pa.getTerme()); | |
18 | + | |
19 | + System.out.print("next (y/n)? "); | |
20 | + next = sc.next().charAt(0); | |
21 | + } | |
22 | + System.out.print("\nnb termes supplementaires? "); | |
23 | + pa.next(sc.nextInt()); | |
24 | + System.out.println("\n"+pa.toString()); | |
25 | + } | |
26 | +} | ... | ... |
... | ... | @@ -0,0 +1,7 @@ |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<classpath> | |
3 | + <classpathentry kind="src" path="src"/> | |
4 | + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | |
5 | + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | |
6 | + <classpathentry kind="output" path="bin"/> | |
7 | +</classpath> | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +/bin/ | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<projectDescription> | |
3 | + <name>tp_bibliotheque</name> | |
4 | + <comment></comment> | |
5 | + <projects> | |
6 | + </projects> | |
7 | + <buildSpec> | |
8 | + <buildCommand> | |
9 | + <name>org.eclipse.jdt.core.javabuilder</name> | |
10 | + <arguments> | |
11 | + </arguments> | |
12 | + </buildCommand> | |
13 | + </buildSpec> | |
14 | + <natures> | |
15 | + <nature>org.eclipse.jdt.core.javanature</nature> | |
16 | + </natures> | |
17 | +</projectDescription> | ... | ... |
tp_bibliotheque/.settings/org.eclipse.jdt.core.prefs
0 → 100644
... | ... | @@ -0,0 +1,11 @@ |
1 | +eclipse.preferences.version=1 | |
2 | +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | |
3 | +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | |
4 | +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | |
5 | +org.eclipse.jdt.core.compiler.compliance=1.8 | |
6 | +org.eclipse.jdt.core.compiler.debug.lineNumber=generate | |
7 | +org.eclipse.jdt.core.compiler.debug.localVariable=generate | |
8 | +org.eclipse.jdt.core.compiler.debug.sourceFile=generate | |
9 | +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | |
10 | +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | |
11 | +org.eclipse.jdt.core.compiler.source=1.8 | ... | ... |
... | ... | @@ -0,0 +1,85 @@ |
1 | +package src; | |
2 | +import java.util.Scanner; | |
3 | + | |
4 | +public class Application { | |
5 | + | |
6 | + static Scanner in = new Scanner(System.in); | |
7 | + public static void main(String[] argv) { | |
8 | + | |
9 | + Bibliotheque bib = new Bibliotheque(); | |
10 | + | |
11 | + //Ranger des ouvrages: | |
12 | + bib.add("I101",new Ouvrage("C","Kernighan")); | |
13 | + bib.add("L202",new Ouvrage("Germinal","Zola")); | |
14 | + bib.add("S303",new Ouvrage("Parapente","Ali Gali")); | |
15 | + bib.add("I345",new Ouvrage("Java","Eckel")); | |
16 | + bib.add("1",new Ouvrage("Test","E")); | |
17 | + bib.add("2",new Revue("Date","Eckel",20180000,1)); | |
18 | + bib.add("3",new Revue("PasDate","Teckel",20180514,1)); | |
19 | + bib.listing(); | |
20 | + | |
21 | + int choix=0; | |
22 | + do { | |
23 | + menu(); | |
24 | + System.out.print("votre choix? "); | |
25 | + choix = in.nextInt(); | |
26 | + switch (choix) { | |
27 | + case 1 : //emprunt | |
28 | + menuEmprunt(bib); | |
29 | + menuListing(bib); | |
30 | + break; | |
31 | + case 2 : //retour | |
32 | + menuRetourner(bib); | |
33 | + menuListing(bib); | |
34 | + break; | |
35 | + | |
36 | + case 3 : //affiche | |
37 | + menuListing(bib); | |
38 | + break; | |
39 | + case 0: // quitter | |
40 | + } | |
41 | + } while (choix!=0); | |
42 | + //Permettre a l'utilisateur d'emprunter/retourner un ouvrage | |
43 | + //en demandant son code. | |
44 | + //Transformer les exceptions en message d'erreur. | |
45 | + | |
46 | + | |
47 | + | |
48 | + | |
49 | + } | |
50 | + | |
51 | + static void menu() { | |
52 | + System.out.println("\n1: Emprunter\n2: Retourner\n3: Lister\n0: quitter"); | |
53 | + } | |
54 | + | |
55 | +static void menuEmprunt(Bibliotheque bib ) { | |
56 | + try{ | |
57 | + System.out.print("\ncode? "); | |
58 | + String code= in.next(); | |
59 | + | |
60 | + bib.emprunter(code); | |
61 | + | |
62 | + }catch (Exception e){ | |
63 | + e.printStackTrace(); | |
64 | + } | |
65 | + | |
66 | + } | |
67 | + | |
68 | + static void menuRetourner(Bibliotheque bib ) { | |
69 | + try{ | |
70 | + | |
71 | + System.out.print("\ncode? "); | |
72 | + String code=in.next(); | |
73 | + | |
74 | + bib.retourner(code); | |
75 | + }catch (OuvrageInconnuException e){ | |
76 | + e.printStackTrace(); | |
77 | + } | |
78 | + | |
79 | + } | |
80 | + | |
81 | + static void menuListing(Bibliotheque bib ) { | |
82 | + bib.listing(); | |
83 | + } | |
84 | + | |
85 | +} | ... | ... |
... | ... | @@ -0,0 +1,70 @@ |
1 | +package src; | |
2 | +import java.util.Map; | |
3 | +import java.util.TreeMap; | |
4 | + | |
5 | +public class Bibliotheque { | |
6 | + | |
7 | +//variables d'instances | |
8 | + protected Map<String,Ouvrage> ouvrages = new TreeMap<String,Ouvrage>(); | |
9 | + static final int date = 20180518; | |
10 | + | |
11 | +//methodes a programmer | |
12 | + public void add(String code, Ouvrage o){ | |
13 | + ouvrages.put(code,o); | |
14 | + | |
15 | + } | |
16 | + | |
17 | + | |
18 | + public int totalEmprunts(){ | |
19 | + int total = 0; | |
20 | + | |
21 | + for (Map.Entry<String, Ouvrage> o: ouvrages.entrySet()) { | |
22 | + Ouvrage ouvrage = o.getValue(); | |
23 | + total += ouvrage.compteur; | |
24 | + } | |
25 | + | |
26 | + return total; | |
27 | + | |
28 | + } | |
29 | + | |
30 | + public void listing(){ | |
31 | + for (Map.Entry<String, Ouvrage> o: ouvrages.entrySet()) { | |
32 | + Ouvrage ouvrage = o.getValue(); | |
33 | + System.out.println(""+ ouvrage.toString()); | |
34 | + } | |
35 | + } | |
36 | + | |
37 | + public void emprunter(String code)throws OuvrageInconnuException,NonDisponibleException,NonDispoException{ | |
38 | + try { | |
39 | + Revue revue = (Revue) ouvrages.get(code); | |
40 | + if(revue == null){ | |
41 | + throw new OuvrageInconnuException(); | |
42 | + } | |
43 | + revue.emprunter(date); | |
44 | + }catch(ClassCastException e){ | |
45 | + //e.printStackTrace(); | |
46 | + Ouvrage ouvrage = ouvrages.get(code); | |
47 | + if(ouvrage == null){ | |
48 | + throw new OuvrageInconnuException(); | |
49 | + } | |
50 | + ouvrage.emprunter(); | |
51 | + } | |
52 | + | |
53 | + | |
54 | + } | |
55 | + | |
56 | + public void retourner(String code)throws OuvrageInconnuException{ | |
57 | + Ouvrage ouvrage = ouvrages.get(code); | |
58 | + if(ouvrage == null){ | |
59 | + throw new OuvrageInconnuException(); | |
60 | + } | |
61 | + ouvrage.retourner(); | |
62 | + | |
63 | + } | |
64 | + | |
65 | + /*public TreeMap<String,Ouvrage> getOuvrage(){ | |
66 | + Arrays.sort(ouvrages, new ComparateurOuvrage()); | |
67 | + }*/ | |
68 | + | |
69 | + | |
70 | +} | ... | ... |
tp_bibliotheque/src/src/NonDisponibleException.java
0 → 100644
... | ... | @@ -0,0 +1,73 @@ |
1 | +package src; | |
2 | + | |
3 | +public class Ouvrage implements Comparable<Ouvrage> { | |
4 | + | |
5 | + // variables d'instance | |
6 | + protected String titre, auteur; | |
7 | + protected boolean emprunte; | |
8 | + protected int compteur; // nombre d'emprunts | |
9 | + | |
10 | + // methodes et constructeurs | |
11 | + public Ouvrage(String tit, String aut) { | |
12 | + this.titre = tit; | |
13 | + this.auteur = aut; | |
14 | + } | |
15 | + | |
16 | + public String toString() { | |
17 | + return "Titre; " + titre + " Auteur; " + auteur + " emprunter: " + emprunte; | |
18 | + } | |
19 | + | |
20 | + public void emprunter() throws NonDisponibleException { | |
21 | + if (this.emprunte == true) { | |
22 | + throw new NonDisponibleException(); | |
23 | + } else { | |
24 | + this.emprunte = true; | |
25 | + this.compteur++; | |
26 | + } | |
27 | + } | |
28 | + | |
29 | + public void retourner() { | |
30 | + this.emprunte = false; | |
31 | + } | |
32 | + | |
33 | + public int getCompteur() { | |
34 | + return this.compteur; | |
35 | + } | |
36 | + | |
37 | + @Override | |
38 | + public int compareTo(Ouvrage ouvrage) { | |
39 | + if (this.compteur <= ouvrage.compteur) { | |
40 | + return -1; | |
41 | + } else { | |
42 | + return 1; | |
43 | + } | |
44 | + } | |
45 | + | |
46 | + public void setTitre(String titre) { | |
47 | + this.titre = titre; | |
48 | + } | |
49 | + | |
50 | + public void setAuteur(String auteur) { | |
51 | + this.auteur = auteur; | |
52 | + } | |
53 | + | |
54 | + public void setEmprunte(boolean emprunte) { | |
55 | + this.emprunte = emprunte; | |
56 | + } | |
57 | + | |
58 | + public void setCompteur(int compteur) { | |
59 | + this.compteur = compteur; | |
60 | + } | |
61 | + | |
62 | + public String getTitre() { | |
63 | + return titre; | |
64 | + } | |
65 | + | |
66 | + public String getAuteur() { | |
67 | + return auteur; | |
68 | + } | |
69 | + | |
70 | + public boolean isEmprunte() { | |
71 | + return emprunte; | |
72 | + } | |
73 | +} | ... | ... |
tp_bibliotheque/src/src/OuvrageInconnuException.java
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +package src; | |
2 | +public class Revue extends Ouvrage { | |
3 | + | |
4 | + protected int dateEdit; | |
5 | + protected int num; | |
6 | + | |
7 | + public Revue(String tit, String aut, int dateEdit, int num){ | |
8 | + super(tit,aut); | |
9 | + this.dateEdit = dateEdit; | |
10 | + this.num = num; | |
11 | + | |
12 | + } | |
13 | + | |
14 | + public void emprunter(int date) throws NonDisponibleException,NonDispoException{ | |
15 | + if(emprunte){ | |
16 | + throw new NonDisponibleException(); | |
17 | + } else { | |
18 | + if(date > dateEdit +7){ | |
19 | + this.emprunte = true; | |
20 | + this.compteur ++; | |
21 | + }else{ | |
22 | + throw new NonDispoException(); | |
23 | + } | |
24 | + } | |
25 | + } | |
26 | + | |
27 | + | |
28 | + | |
29 | +} | ... | ... |
... | ... | @@ -0,0 +1,45 @@ |
1 | +package test; | |
2 | + | |
3 | + | |
4 | +import static org.junit.Assert.assertTrue; | |
5 | + | |
6 | +import org.junit.Before; | |
7 | +import org.junit.Test; | |
8 | + | |
9 | +import src.NonDisponibleException; | |
10 | +import src.Ouvrage; | |
11 | + | |
12 | +public class OuvrageTest { | |
13 | + | |
14 | + public Ouvrage o; | |
15 | + | |
16 | + @Before | |
17 | + public void initVals(){ | |
18 | + o = new Ouvrage("test","vinz"); | |
19 | + } | |
20 | + | |
21 | + @Test | |
22 | + public void emprunterValeurEmprunteTest() throws NonDisponibleException{ | |
23 | + assertTrue(o.isEmprunte()==false); | |
24 | + o.emprunter(); | |
25 | + | |
26 | + assertTrue(o.isEmprunte()==true); | |
27 | + | |
28 | + } | |
29 | + | |
30 | + @Test | |
31 | + public void emprunterValeurCompteurTest() throws NonDisponibleException{ | |
32 | + assertTrue(o.getCompteur()==0); | |
33 | + o.emprunter(); | |
34 | + | |
35 | + assertTrue(o.getCompteur()==1); | |
36 | + | |
37 | + } | |
38 | + | |
39 | + @Test(expected = NonDisponibleException.class) | |
40 | + public void emprunterExceptionLanceeTest() throws NonDisponibleException{ | |
41 | + o.emprunter(); | |
42 | + o.emprunter(); | |
43 | + } | |
44 | + | |
45 | +} | ... | ... |
... | ... | @@ -0,0 +1,47 @@ |
1 | +package test; | |
2 | + | |
3 | + | |
4 | +import static org.junit.Assert.assertTrue; | |
5 | + | |
6 | +import org.junit.Before; | |
7 | +import org.junit.Test; | |
8 | +import src.*; | |
9 | + | |
10 | +public class RevueTest { | |
11 | + | |
12 | + public Ouvrage o; | |
13 | + public Revue r1; | |
14 | + public Revue r2; | |
15 | + | |
16 | + @Before | |
17 | + public void initVals(){ | |
18 | + o = new Ouvrage("test","vinz"); | |
19 | + r1 = new Revue("test2", "vinz", 20180500, 1); | |
20 | + r2 = new Revue("test2", "vinz", 20180517, 1); | |
21 | + } | |
22 | + | |
23 | + @Test | |
24 | + public void emprunterValeurEmprunteTest() throws NonDisponibleException{ | |
25 | + assertTrue(r1.isEmprunte()==false); | |
26 | + r1.emprunter(); | |
27 | + | |
28 | + assertTrue(r1.isEmprunte()==true); | |
29 | + | |
30 | + } | |
31 | + | |
32 | + @Test | |
33 | + public void emprunterValeurCompteurTest() throws NonDisponibleException{ | |
34 | + assertTrue(r1.getCompteur()==0); | |
35 | + r1.emprunter(); | |
36 | + | |
37 | + assertTrue(r1.getCompteur()==1); | |
38 | + | |
39 | + } | |
40 | + | |
41 | + @Test(expected = NonDispoException.class) | |
42 | + public void emprunterExceptionLanceeTest() throws NonDispoException, NonDisponibleException{ | |
43 | + r2.emprunter(20180518); | |
44 | + | |
45 | + } | |
46 | + | |
47 | +} | ... | ... |