Commit fed1c83c49ea1a726cfc2e492ba464a371483146
1 parent
f98eb12b
tp2 et 3
Showing
49 changed files
with
644 additions
and
0 deletions
Show diff stats
No preview for this file type
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +public class Banque{ | ||
2 | + | ||
3 | + public void crediter(Compte c, double valeur){ | ||
4 | + c.crediter(valeur); | ||
5 | + } | ||
6 | + | ||
7 | + public void debiter(Compte c, double valeur){ | ||
8 | + c.debiter(valeur); | ||
9 | + } | ||
10 | + | ||
11 | + public String etat(Compte c){ | ||
12 | + return c.toString(); | ||
13 | + } | ||
14 | + | ||
15 | +} |
No preview for this file type
@@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
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 "Votre solde actuel est de "+solde()+" ("+getCredit()+" - "+getDebit()+")"; | ||
45 | + } | ||
46 | + | ||
47 | +} |
No preview for this file type
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
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 | +// return (soldeCredit()-soldeDebit())*getInteret(); | ||
17 | + } | ||
18 | + | ||
19 | + public void echeance(){ | ||
20 | + crediter(interets()); | ||
21 | + } | ||
22 | + | ||
23 | + public void debiter(double val){ | ||
24 | + if((getCredit()-val)>0){ | ||
25 | + setDebit(getDebit()+val); | ||
26 | + | ||
27 | + } | ||
28 | + } | ||
29 | + | ||
30 | + public CompteEpargne(double creditInit, double interet){ | ||
31 | + super(creditInit); | ||
32 | + setInteret(interet); | ||
33 | + } | ||
34 | + | ||
35 | + public CompteEpargne(){ | ||
36 | + super(); | ||
37 | + setInteret(0.1); | ||
38 | + } | ||
39 | + | ||
40 | + public String etat(){ | ||
41 | + return super.toString()+" Interets du mois: "+ interets(); | ||
42 | + } | ||
43 | + | ||
44 | +} |
No preview for this file type
@@ -0,0 +1,40 @@ | @@ -0,0 +1,40 @@ | ||
1 | + | ||
2 | + | ||
3 | +public class TestComptes{ | ||
4 | + | ||
5 | + public static void main(String[] args){ | ||
6 | + | ||
7 | + Compte unCompte = new Compte(); | ||
8 | + CompteEpargne unCE = new CompteEpargne(); | ||
9 | + System.out.println(unCompte.toString()); | ||
10 | + System.out.println(unCE.toString()); | ||
11 | + | ||
12 | + unCompte.crediter(100.0); | ||
13 | + unCE.crediter(200.0); | ||
14 | + | ||
15 | + System.out.println(unCompte.toString()); | ||
16 | + System.out.println(unCE.toString()); | ||
17 | + //unCompte.etat(); | ||
18 | + System.out.println(unCE.etat()); | ||
19 | + | ||
20 | + //unCE=unCompte; -> incompatibletype | ||
21 | + | ||
22 | + | ||
23 | + Banque b = new Banque(); | ||
24 | + b.crediter(unCompte, 10); | ||
25 | + b.debiter(unCompte, 235); | ||
26 | + System.out.println(b.etat(unCompte)); | ||
27 | + | ||
28 | + b.crediter(unCE, 10); | ||
29 | + b.debiter(unCE, 235); | ||
30 | + System.out.println(b.etat(unCE)); | ||
31 | + | ||
32 | + unCompte=unCE; | ||
33 | + | ||
34 | + b.crediter(unCompte, 10); | ||
35 | + b.debiter(unCompte, 235); | ||
36 | + System.out.println(b.etat(unCompte)); | ||
37 | + } | ||
38 | + | ||
39 | + | ||
40 | +} |
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,114 @@ | @@ -0,0 +1,114 @@ | ||
1 | + | ||
2 | + | ||
3 | +public class Compte { | ||
4 | + | ||
5 | + int MAX_OPERATIONS = 10; | ||
6 | + | ||
7 | + private double credits[] = new double[MAX_OPERATIONS]; | ||
8 | + private double debits[] = new double[MAX_OPERATIONS]; | ||
9 | + private int dernierCredit=0; | ||
10 | + private int dernierDebit=0; | ||
11 | + | ||
12 | + public Compte(){ | ||
13 | + | ||
14 | + } | ||
15 | + | ||
16 | + public Compte(double x){ | ||
17 | + crediter(x); | ||
18 | + } | ||
19 | + | ||
20 | + | ||
21 | + public int getDernierCredit(){ | ||
22 | + return dernierCredit; | ||
23 | + } | ||
24 | + | ||
25 | + public int getDernierDebit(){ | ||
26 | + return dernierDebit; | ||
27 | + } | ||
28 | + | ||
29 | + public void setDernierCredit(int i){ | ||
30 | + this.dernierCredit=i; | ||
31 | + } | ||
32 | + | ||
33 | + public void setDernierDebit(int i){ | ||
34 | + this.dernierDebit=i; | ||
35 | + } | ||
36 | + | ||
37 | + public double getCredit(int indice){ | ||
38 | + return credits[indice]; | ||
39 | + } | ||
40 | + | ||
41 | + public double getDebit(int indice){ | ||
42 | + return debits[indice]; | ||
43 | + } | ||
44 | + | ||
45 | + public void setCredit(int indice, double d){ | ||
46 | + credits[indice]=d; | ||
47 | + } | ||
48 | + | ||
49 | + public void setDebit(int indice, double d){ | ||
50 | + debits[indice]=d; | ||
51 | + } | ||
52 | + | ||
53 | + public void crediter(double x){ | ||
54 | + if(getDernierCredit()+1>MAX_OPERATIONS){ | ||
55 | + double sd = soldeCredit(); | ||
56 | + this.credits = new double[MAX_OPERATIONS]; | ||
57 | + setCredit(0, sd); | ||
58 | + } else { | ||
59 | + setCredit(getDernierCredit(),x); | ||
60 | + setDernierCredit(getDernierCredit()+1); | ||
61 | + } | ||
62 | + } | ||
63 | + | ||
64 | + public void debiter(double x){ | ||
65 | + | ||
66 | + | ||
67 | + if(getDernierDebit()+1>MAX_OPERATIONS){ | ||
68 | + double sd = soldeDebit(); | ||
69 | + this.debits = new double[MAX_OPERATIONS]; | ||
70 | + setDebit(0, sd); | ||
71 | + } else { | ||
72 | + setDebit(getDernierDebit(),x); | ||
73 | + setDernierDebit(getDernierDebit()+1); | ||
74 | + } | ||
75 | + } | ||
76 | + | ||
77 | + public double soldeCredit(){ | ||
78 | + double res = 0; | ||
79 | + if(getDernierCredit()>0){ | ||
80 | + for(int i = 0; i<=getDernierCredit(); i++){ | ||
81 | + res+=getCredit(i); | ||
82 | + } | ||
83 | + } | ||
84 | + return res; | ||
85 | + } | ||
86 | + | ||
87 | + public double soldeDebit(){ | ||
88 | + double res = 0; | ||
89 | + if(getDernierDebit()>0){ | ||
90 | + for(int i = 0; i<=getDernierDebit(); i++){ | ||
91 | + res+=getDebit(i); | ||
92 | + } | ||
93 | + } | ||
94 | + return res; | ||
95 | + } | ||
96 | + | ||
97 | + public double solde(){ | ||
98 | + return soldeCredit()-soldeDebit(); | ||
99 | + } | ||
100 | + | ||
101 | + public String toString(){ | ||
102 | + String res=""; | ||
103 | + for(int i = 0; i<=getDernierCredit(); i++){ | ||
104 | + res+="Credit"+i+"= "+getCredit(i)+"\n"; | ||
105 | + } | ||
106 | + res+="\n"; | ||
107 | + for(int i = 0; i<=getDernierDebit(); i++){ | ||
108 | + res+="Debit"+i+"= "+getDebit(i)+"\n"; | ||
109 | + } | ||
110 | + res+="\nSolde final:"+solde()+".\n"; | ||
111 | + return res; | ||
112 | + } | ||
113 | + | ||
114 | +} |
No preview for this file type
tp2_banques/tp2/operations_historisees/CompteEpargne.java
0 → 100644
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
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 | + return (soldeCredit()-soldeDebit())*getInteret(); | ||
17 | + } | ||
18 | + | ||
19 | + public void echeance(){ | ||
20 | + crediter(interets()); | ||
21 | + } | ||
22 | + | ||
23 | + public void debiter(double val){ | ||
24 | + if((soldeCredit()-val)>0){ | ||
25 | + super.debiter(soldeDebit()+val); | ||
26 | + | ||
27 | + } | ||
28 | + } | ||
29 | + | ||
30 | + public CompteEpargne(double creditInit, double interet){ | ||
31 | + super(creditInit); | ||
32 | + setInteret(interet); | ||
33 | + } | ||
34 | + | ||
35 | + public CompteEpargne(){ | ||
36 | + super(); | ||
37 | + setInteret(0.1); | ||
38 | + } | ||
39 | + | ||
40 | + public String etat(){ | ||
41 | + return super.toString()+" Interets du mois: "+ interets(); | ||
42 | + } | ||
43 | + | ||
44 | +} |
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
tp3_polymorph/tp3/arithmetic/ProgressionArithmetique.java
0 → 100644
@@ -0,0 +1,65 @@ | @@ -0,0 +1,65 @@ | ||
1 | +import java.util.*; | ||
2 | + | ||
3 | +public class ProgressionArithmetique { | ||
4 | + | ||
5 | + ArrayList<Double> termes; | ||
6 | + double raison; | ||
7 | + int rang; | ||
8 | + | ||
9 | + | ||
10 | + public ProgressionArithmetique(double terme1, double raison){ | ||
11 | + termes = new ArrayList<Double>(); | ||
12 | + termes.add(terme1); | ||
13 | + this.setRang(0); | ||
14 | + this.setRaison(raison); | ||
15 | + } | ||
16 | + | ||
17 | + public int getRang(){ | ||
18 | + return this.rang; | ||
19 | + } | ||
20 | + | ||
21 | + public void setRang(int rang){ | ||
22 | + this.rang = rang; | ||
23 | + } | ||
24 | + | ||
25 | + public double getRaison(){ | ||
26 | + return this.raison; | ||
27 | + } | ||
28 | + | ||
29 | + public void setRaison(double raison){ | ||
30 | + this.raison = raison; | ||
31 | + } | ||
32 | + | ||
33 | + | ||
34 | + void next(){ | ||
35 | + double d = this.termes.get(getRang()); | ||
36 | + d += raison; | ||
37 | + termes.add(d); | ||
38 | + rang++; | ||
39 | + } | ||
40 | + | ||
41 | + | ||
42 | + /** | ||
43 | + Calcul les n prochaines itérations | ||
44 | + */ | ||
45 | + void next(int n){ | ||
46 | + for(int i =0; i<n;i++){ | ||
47 | + next(); | ||
48 | + } | ||
49 | + } | ||
50 | + | ||
51 | + /** | ||
52 | + Récupère le dernier terme | ||
53 | + */ | ||
54 | + public double getTerme(){ | ||
55 | + return termes.get(getRang()); | ||
56 | + } | ||
57 | + | ||
58 | + public String toString(){ | ||
59 | + String res ="progression:"; | ||
60 | + for (Double d: termes) { | ||
61 | + res+= " "+d; | ||
62 | + } | ||
63 | + return res; | ||
64 | + } | ||
65 | +} |
No preview for this file type
@@ -0,0 +1,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 | +} |
No preview for this file type
tp3_polymorph/tp3/geometric/ProgressionGeometrique.java
0 → 100644
@@ -0,0 +1,65 @@ | @@ -0,0 +1,65 @@ | ||
1 | +import java.util.*; | ||
2 | + | ||
3 | +public class ProgressionGeometrique { | ||
4 | + | ||
5 | + ArrayList<Double> termes; | ||
6 | + double raison; | ||
7 | + int rang; | ||
8 | + | ||
9 | + | ||
10 | + public ProgressionGeometrique(double terme1, double raison){ | ||
11 | + termes = new ArrayList<Double>(); | ||
12 | + termes.add(terme1); | ||
13 | + this.setRang(0); | ||
14 | + this.setRaison(raison); | ||
15 | + } | ||
16 | + | ||
17 | + public int getRang(){ | ||
18 | + return this.rang; | ||
19 | + } | ||
20 | + | ||
21 | + public void setRang(int rang){ | ||
22 | + this.rang = rang; | ||
23 | + } | ||
24 | + | ||
25 | + public double getRaison(){ | ||
26 | + return this.raison; | ||
27 | + } | ||
28 | + | ||
29 | + public void setRaison(double raison){ | ||
30 | + this.raison = raison; | ||
31 | + } | ||
32 | + | ||
33 | + | ||
34 | + void next(){ | ||
35 | + double d = this.termes.get(getRang()); | ||
36 | + d *= raison; | ||
37 | + termes.add(d); | ||
38 | + rang++; | ||
39 | + } | ||
40 | + | ||
41 | + | ||
42 | + /** | ||
43 | + Calcul les n prochaines itérations | ||
44 | + */ | ||
45 | + void next(int n){ | ||
46 | + for(int i =0; i<n;i++){ | ||
47 | + next(); | ||
48 | + } | ||
49 | + } | ||
50 | + | ||
51 | + /** | ||
52 | + Récupère le dernier terme | ||
53 | + */ | ||
54 | + public double getTerme(){ | ||
55 | + return termes.get(getRang()); | ||
56 | + } | ||
57 | + | ||
58 | + public String toString(){ | ||
59 | + String res ="progression:"; | ||
60 | + for (Double d: termes) { | ||
61 | + res+= " "+d; | ||
62 | + } | ||
63 | + return res; | ||
64 | + } | ||
65 | +} |
No preview for this file type
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +import java.util.*; | ||
2 | + | ||
3 | +public class TestGeometrique { | ||
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 | + ProgressionGeometrique pg = new ProgressionGeometrique(d,raison); | ||
12 | + | ||
13 | + System.out.print("\nnext (y/n)? "); | ||
14 | + char next = sc.next().charAt(0); | ||
15 | + while(next == 'y'){ | ||
16 | + pg.next(); | ||
17 | + System.out.println("\n-> "+pg.getTerme()); | ||
18 | + | ||
19 | + System.out.print("next (y/n)? "); | ||
20 | + next = sc.next().charAt(0); | ||
21 | + } | ||
22 | + System.out.print("\nnb termes supplementaires? "); | ||
23 | + pg.next(sc.nextInt()); | ||
24 | + System.out.println("\n"+pg.toString()); | ||
25 | + } | ||
26 | +} |
No preview for this file type
@@ -0,0 +1,60 @@ | @@ -0,0 +1,60 @@ | ||
1 | +import java.util.*; | ||
2 | + | ||
3 | +public abstract class Progression{ | ||
4 | + | ||
5 | + ArrayList<Double> termes; | ||
6 | + double raison; | ||
7 | + int rang; | ||
8 | + | ||
9 | + | ||
10 | + public Progression(double terme1, double raison){ | ||
11 | + termes = new ArrayList<Double>(); | ||
12 | + termes.add(terme1); | ||
13 | + this.setRang(0); | ||
14 | + this.setRaison(raison); | ||
15 | + } | ||
16 | + | ||
17 | + public int getRang(){ | ||
18 | + return this.rang; | ||
19 | + } | ||
20 | + | ||
21 | + public void setRang(int rang){ | ||
22 | + this.rang = rang; | ||
23 | + } | ||
24 | + | ||
25 | + public double getRaison(){ | ||
26 | + return this.raison; | ||
27 | + } | ||
28 | + | ||
29 | + public void setRaison(double raison){ | ||
30 | + this.raison = raison; | ||
31 | + } | ||
32 | + | ||
33 | + | ||
34 | + abstract void next(); | ||
35 | + | ||
36 | + | ||
37 | + /** | ||
38 | + Calcul les n prochaines itérations | ||
39 | + */ | ||
40 | + void next(int n){ | ||
41 | + for(int i =0; i<n;i++){ | ||
42 | + next(); | ||
43 | + } | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + Récupère le dernier terme | ||
48 | + */ | ||
49 | + public double getTerme(){ | ||
50 | + return termes.get(getRang()); | ||
51 | + } | ||
52 | + | ||
53 | + public String toString(){ | ||
54 | + String res ="progression:"; | ||
55 | + for (Double d: termes) { | ||
56 | + res+= " "+d; | ||
57 | + } | ||
58 | + return res; | ||
59 | + } | ||
60 | +} |
No preview for this file type
tp3_polymorph/tp3/hierarchic/ProgressionArithmetique.java
0 → 100644
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +import java.util.*; | ||
2 | + | ||
3 | +public class ProgressionArithmetique extends Progression{ | ||
4 | + | ||
5 | + public ProgressionArithmetique(double terme1, double raison){ | ||
6 | + super(terme1,raison); | ||
7 | + } | ||
8 | + | ||
9 | + void next(){ | ||
10 | + double d = this.termes.get(getRang()); | ||
11 | + d += raison; | ||
12 | + termes.add(d); | ||
13 | + rang++; | ||
14 | + } | ||
15 | + | ||
16 | +} |
No preview for this file type
tp3_polymorph/tp3/hierarchic/ProgressionGeometrique.java
0 → 100644
@@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
1 | +import java.util.*; | ||
2 | + | ||
3 | +public class ProgressionGeometrique extends Progression{ | ||
4 | + | ||
5 | + | ||
6 | + public ProgressionGeometrique(double terme1, double raison){ | ||
7 | + super(terme1,raison); | ||
8 | + } | ||
9 | + | ||
10 | + void next(){ | ||
11 | + double d = this.termes.get(getRang()); | ||
12 | + d *= raison; | ||
13 | + termes.add(d); | ||
14 | + rang++; | ||
15 | + } | ||
16 | + | ||
17 | +} |
No preview for this file type
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +import java.util.*; | ||
2 | + | ||
3 | +public class Test{ | ||
4 | + | ||
5 | + | ||
6 | + | ||
7 | + | ||
8 | + | ||
9 | + public static void main(String[] args){ | ||
10 | + Scanner sc = new Scanner(System.in); | ||
11 | + //Choix Progression | ||
12 | + System.out.println("Arithmetique taper 1\n Geometrique taper 2 "); | ||
13 | + int choix = sc.nextInt(); | ||
14 | + | ||
15 | + System.out.print("\npremier terme? "); | ||
16 | + double d = sc.nextDouble(); | ||
17 | + System.out.print("\nraison? "); | ||
18 | + double raison = sc.nextDouble(); | ||
19 | + Progression p; | ||
20 | + | ||
21 | + if(choix == 1){ | ||
22 | + p= new ProgressionArithmetique(d,raison); | ||
23 | + } else { | ||
24 | + p= new ProgressionGeometrique(d,raison); | ||
25 | + } | ||
26 | + manip(p); | ||
27 | + | ||
28 | + | ||
29 | + | ||
30 | + | ||
31 | + } | ||
32 | + | ||
33 | + | ||
34 | + static void manip(Progression p){ | ||
35 | + | ||
36 | + Scanner sc = new Scanner(System.in); | ||
37 | + System.out.print("\nnext (y/n)? "); | ||
38 | + char next = sc.next().charAt(0); | ||
39 | + while(next == 'y'){ | ||
40 | + p.next(); | ||
41 | + System.out.println("\n-> "+p.getTerme()); | ||
42 | + | ||
43 | + System.out.print("next (y/n)? "); | ||
44 | + next = sc.next().charAt(0); | ||
45 | + } | ||
46 | + System.out.print("\nnb termes supplementaires? "); | ||
47 | + p.next(sc.nextInt()); | ||
48 | + System.out.println("\n"+p.toString()); | ||
49 | + } | ||
50 | + | ||
51 | +} |
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