Blame view

tp2_banques/tp2/operations_historisees/Compte.java 2.56 KB
fed1c83c   Vincent Benoist   tp2 et 3
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
  
  
  public class Compte {
  
      int MAX_OPERATIONS = 10;
      
      private double credits[] = new double[MAX_OPERATIONS];
      private double debits[] = new double[MAX_OPERATIONS];
      private int dernierCredit=0;
      private int dernierDebit=0;
      
      public Compte(){
      
      }
      
      public Compte(double x){
          crediter(x);
      }
      
      
      public int getDernierCredit(){
          return dernierCredit;
      }
      
      public int getDernierDebit(){
          return dernierDebit;
      }
      
      public void setDernierCredit(int i){
         this.dernierCredit=i;
      }
      
      public void setDernierDebit(int i){
          this.dernierDebit=i;
      }
      
      public double getCredit(int indice){
          return credits[indice];
      }
      
      public double getDebit(int indice){
          return debits[indice];
      }
      
      public void setCredit(int indice, double d){
         credits[indice]=d;
      }
      
      public void setDebit(int indice, double d){
          debits[indice]=d;
      }
      
      public void crediter(double x){
          if(getDernierCredit()+1>MAX_OPERATIONS){
              double sd = soldeCredit();
              this.credits = new double[MAX_OPERATIONS];
              setCredit(0, sd);
          } else {
              setCredit(getDernierCredit(),x);
              setDernierCredit(getDernierCredit()+1);
          }
      }
  
     public void debiter(double x){
         
          
          if(getDernierDebit()+1>MAX_OPERATIONS){
              double sd = soldeDebit();
              this.debits = new double[MAX_OPERATIONS];
              setDebit(0, sd);
          } else {
              setDebit(getDernierDebit(),x);
              setDernierDebit(getDernierDebit()+1);
          }
      }
      
      public double soldeCredit(){
          double res = 0;
          if(getDernierCredit()>0){
              for(int i = 0; i<=getDernierCredit(); i++){
                  res+=getCredit(i);
              }
          }  
          return res;
      }
      
      public double soldeDebit(){
          double res = 0;
          if(getDernierDebit()>0){
              for(int i = 0; i<=getDernierDebit(); i++){
                  res+=getDebit(i);
              }
          }  
          return res;
      }
      
      public double solde(){
          return soldeCredit()-soldeDebit();
      }
      
      public String toString(){
          String res="";
          for(int i = 0; i<=getDernierCredit(); i++){
              res+="Credit"+i+"= "+getCredit(i)+"\n";
          }
          res+="\n";
          for(int i = 0; i<=getDernierDebit(); i++){
              res+="Debit"+i+"= "+getDebit(i)+"\n";
          }
          res+="\nSolde final:"+solde()+".\n";
          return res;
      }
      
  }