Exercice Visual Basic : TP Banque
Rédigé par GC Team, Publié le 07 Janvier 2012, Mise à jour le Samedi, 17 Décembre 2022 16:34
Participez au vote ☆☆☆☆☆★★★★★

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 |
Public Class banque Private nom As String Private col As New Hashtable Shared numeroCompte As Integer = 100 Private taux As Double = 0.05 Sub New() End Sub Sub New(ByVal _nom As String) nom = _nom End Sub Function getCompt(ByVal numero As Integer) As compte If col.ContainsKey(numero) Then Return col(numero) End If Return Nothing End Function Sub addCompte(ByVal montant As Double) numeroCompte += 1 Dim cpt As New compte(numeroCompte, montant) col.Add(cpt._numéro, cpt) End Sub Sub add_comptEpagne(ByVal montant As Double) numeroCompte += 1 Dim cpt As New CompteEpargne(numeroCompte, montant, taux) col.Add(cpt._numéro, cpt) End Sub Sub visualiser() Console.WriteLine("Banque " & nom) For Each compte In col.Values compte.afficher() Next End Sub Sub fermerCompte(ByVal Num As Integer) Dim cpt As compte = getCompt(Num) If cpt Is Nothing Then Console.WriteLine("Compte introuvable") Else col.Remove(cpt) End If End Sub Sub calculInteret() For Each cpt In col.Values Dim comp As compte comp = cpt If TypeOf (comp) Is CompteEpargne Then cpt.calculeinteret() End If Next End Sub Sub débiter(ByVal Num As Integer, ByVal montant As Double) Dim cpt As compte = getCompt(Num) If cpt Is Nothing Then Console.WriteLine("Compte introuvable") Else cpt.dèbiter(montant) End If End Sub Sub créditer(ByVal Num As Integer, ByVal montant As Double) Dim cpt As compte = getCompt(Num) If cpt Is Nothing Then Console.WriteLine("Compte introuvable") Else cpt.crèditer(montant) End If End Sub End Class ----------------------------------------------------------------------------- Public Class compte Private numéro As Integer Private solde As Double Public listoperation(9) As opération Dim nb As Integer = 0 Property _numéro() As Integer Get Return numéro End Get Set(ByVal value As Integer) value = numéro End Set End Property Property _solde() As Double Get Return solde End Get Set(ByVal value As Double) value = solde End Set End Property Sub New() End Sub Sub New(ByVal _numéro As Integer, ByVal _solde As Double) numéro = _numéro solde = _solde End Sub Public Overridable Sub afficher() Console.WriteLine(numéro & vbTab & solde) End Sub Sub dèbiter(ByVal montant As Double) If solde < montant Then Console.WriteLine(" le solde est insuffisant") Else solde -= montant End If End Sub Sub crèditer(ByVal montant As Double) solde += montant End Sub Sub ajoutopèration(ByVal type As String, ByVal montant As Double) listoperation(nb Mod 10) = New opération(type, montant) nb += 1 End Sub Sub editerreleve() afficher() Dim op As opération For i = 0 To listoperation.GetUpperBound(0) op = listoperation(i) op.affiche() Next End Sub Protected Overrides Sub Finalize() Console.WriteLine("un compte est fermé") End Sub End Class ----------------------------------------------------------------------------- Public Class CompteEpargne Inherits compte Private taux_int As Double Private interet As Double Property _taux_int() Get Return taux_int End Get Set(ByVal value) value = taux_int End Set End Property Property _interet() Get Return interet End Get Set(ByVal value) value = interet End Set End Property Sub New() End Sub Sub New(ByVal numéro As Double, ByVal _solde As Double, ByVal _taux_int As Double) MyBase.New(numéro, _solde) taux_int = _taux_int End Sub Public Sub calculeinteret() crèditer(_solde * taux_int) interet = _solde * taux_int End Sub Public Overrides Sub afficher() MyBase.afficher() Console.WriteLine(vbTab & vbTab & interet & vbTab & taux_int) End Sub Protected Overrides Sub Finalize() Console.WriteLine("un compte est fermé") End Sub End Class ----------------------------------------------------------------------------( Public Class opération Private type As String Private dat As Date Private montant As Double Property _type() As String Get Return type End Get Set(ByVal value As String) value = type End Set End Property Property _dat() As Date Get Return dat End Get Set(ByVal value As Date) value = dat End Set End Property Property _montant() As Double Get Return montant End Get Set(ByVal value As Double) value = montant End Set End Property Sub New() End Sub Sub New(ByVal _type As String, ByVal _montant As Double) type = _type dat = Date.Now montant = _montant End Sub Public Sub affiche() Console.WriteLine(type & vbTab & dat & vbTab & montant) End Sub End Class ----------------------------------------------------------------------------- Module Module1 Sub Main() Dim bank As New banque("MA BANQUE") bank.addCompte(5000) bank.addCompte(6000) bank.add_comptEpagne(3000) bank.créditer(101, 500) bank.débiter(102, 1000) bank.calculInteret() bank.visualiser() Console.ReadLine() End Sub End Module |
