From 6dbbe2a1ede487cf511ea06a56bcc69ea6575070 Mon Sep 17 00:00:00 2001 From: "mathias.catala" <catalamathias@gmail.com> Date: Sat, 25 Nov 2023 19:48:39 +0100 Subject: [PATCH] "update" --- bancomat.scala | 271 ++++++++++++++++++++++++++++-------------------- bancomat2.scala | 124 ++++++++++++++++++++++ 2 files changed, 285 insertions(+), 110 deletions(-) create mode 100644 bancomat2.scala diff --git a/bancomat.scala b/bancomat.scala index 1b42255..42b2dc4 100644 --- a/bancomat.scala +++ b/bancomat.scala @@ -1,129 +1,180 @@ + import scala.io.StdIn._ +import scala.collection.mutable.ArrayBuffer object Main{ - - var continuer = true def main(args: Array[String]): Unit = { - var pincorrect = Array("a","b","c","d","e") + var pincorrect = "f" var pin="" var continuer = true - var montantinitial = 1200.0 - - var comptes= Array(montantinitial,montantinitial,montantinitial,montantinitial,montantinitial) - - var nbclient = comptes.length - println("nbclient"+ nbclient) - var check = 0 - - var tentative = 0 - var choix = 0 - var monID = 0 - - println("Saisissez votre code identifiant >") - monID = readLine().toInt - - - while(monID>nbclient){ - println("Cet identifiant n'est pas valable.") - println("Saisissez votre code identifiant >") - monID = readLine().toInt - - } - //demander a l'utilisateu le pin + var depot = 0 + var consultation = 0 + var montantdeposer = 0 + var devise=0 + var choix =0 + var montantderetrait = 0.0 + var coupures = 0 + var montantdisponible = 1200.0; + + + while (continuer) + { + + + //demander a l'utilisateu le pin println("Saisissez votre code pin > ") - pin = readLine("quel est votre pin? >") - if(pin == pincorrect(monID-1)){ + pin = readLine() + if(pin == pincorrect){ //afficher les operation //demander a l'utilisateu de choisir une operation - println("Code correct !") - }else { - while (tentative < 3&&pin!=pincorrect) { + println("Choisissez votre opération:") + println("1. Dépôt") + println("2. Consultation") + println("3. Retrait") + println("4. Terminer") + println("Entrez le numéro de l'opération: ") + choix = readLine().toInt + continuer =false + } + else { + while (tentative < 3&&pin!=pincorrect) { + + println("Il faut saisir un pin correct > ") + pin = readLine() + tentative += 1 + } + } + if(tentative==3 && pin!=pincorrect){ + println("Pour votre protection, les opérations bancaires vont s'interrompre, récupérez votre carte") + continuer = false + } - println("Il faut saisir un pin correct > ") - pin = readLine() - tentative += 1 - println("Code pin erroné, il vous reste " + tentative + " tentatives >") - } + + if(choix == 1 ){ + continuer= true + while(continuer){ + println ("<Opération de dépot> : ") + println("quelle est la devise: 1 pour CHF et 2 pour EUR? ") + devise = readLine().toInt + if(devise == 1 || devise == 2){ + println("quelle est le montant a deposer?") + montantdeposer = readInt() + if(montantdeposer %10 == 0){ + continuer= false + } + else{ + println("Impossible") + } + } + if(devise!=2|| montantdeposer %10 != 0 ) { + if(montantdeposer%10!=0||devise!=1) + println("operation impossible") + } + } + if(devise== 1|| devise == 2){ + if(devise==1&&montantdeposer %10 == 0 ){ + println("operation reussie; "+"montantdisponible" + montantdeposer) + } else { + println("operation impossible") + } + if( devise==2&& montantdeposer %10 == 0){ + println ("montantdisponible " + 0.95*montantdeposer) + } + if(devise!=2|| montantdeposer %10 != 0) { + if(montantdeposer%10!=0||devise!=1) + println("operation impossible") + } + montantdisponible+=montantdeposer + printf("Votre depot a été pris en compte, le nouveau montant disponible sur votre compte est : %.2f CHF\n", montantdisponible) } - if(tentative==3 && pin!=pincorrect){ - println("Trop d'erreurs, abandon de l'identification") - } - while(continuer){ - //afficher les operation - println("Choisissez votre opération:") - println("1. Dépôt") - println("2. Consultation") - println("3. Retrait") - println("4. Changement du pin") - println("5. Terminer") - println("Entrez le numéro de l'opération: ") - choix = readLine().toInt - - if(choix == 1 ){ - depot(monID, comptes) - } - if (choix == 2) {printf("la valeur de montantdisponible : %.2f \n", comptes(monID) )} - if(choix == 3 ){ // si le client veut retirer de l'argent - retrait(monID, comptes) - continuer =false - } - if(choix ==4 ){ - changepin(monID, pincorrect) - } - if(choix ==5 ){ - println("Fin des opérations, n'oubliez pas de récupérer votre carte.") - } - } - } - - - def retrait(id : Int, comptes: Array[Double]) : Unit={ - var devise = 0 - var montantderetrait = 0 - var coupures = 0 - var correct =true + } - println("quelle est la devise: 1 pour CHF et 2 pour EUR? ") - devise = readLine().toInt - println("quelle est le montant a retirer?") - montantderetrait = readLine().toInt - if(montantderetrait %10 == 0){ - if(devise== 1){ - println("choisissez la coupure: 1 pour petite et 2 pour grande") - coupures = readInt() + + if (choix == 2) { + printf("la valeur de montantdisponible : %.2f \n", montantdisponible ) + } + } + + + if(choix == 3){ + // si le client veut retirer de l'argent + println ("<Opération de retrait> : ") + continuer= true + var i = 0 + var k= 0 + var small = 0 + var check = "" + var deviseprint = "CHF" + var coupuresList = Array(500,200,100,50,20,10) + val coupurescount = ArrayBuffer[Int]() + var plafond = 0.10*montantdisponible + var reste = 0 + while(continuer){ + println("quelle est la devise: 1 pour CHF et 2 pour EUR? ") + devise = readLine().toInt + println("quelle est le montant a retirer?") + montantderetrait = readInt() + + while (montantderetrait %10 != 0 || montantderetrait< plafond){ + println("Le montant doit être un multiple de 10") + println("Votre plafond de retrait autorisé est de :" + plafond) + println("quelle est le montant a retirer?") + montantderetrait = readDouble() + } - comptes(id)-= montantderetrait*1.05 - printf("Votre retrait a été pris en compte, le nouveau montant disponible sur votre compte est : %.2f CHF\n", comptes(id)) - - } - else{println("operation impossible")} - } + if (devise ==1 && montantderetrait<200 ){ + coupures=1 + }else if (devise ==1){ + println("choisissez la coupure: 1 pour petites et 2 pour grandes") + coupures = readInt() + + } + + if(devise ==2){ + deviseprint = "EUR" + montantderetrait*=1.05 + } - def depot(id :Int, comptes : Array[Double]): Unit={ - var devise = 0 - var montantdeposer = 0 + if(coupures==2){ + i = 0 + }else if (coupures==1 || devise ==2 ) { + i =2 + small =2 + + } - println("quelle est la devise: 1 pour CHF et 2 pour EUR? ") - devise = readInt() - println("quelle est le montant a deposer?") - montantdeposer = readInt() - if(montantdeposer %10 == 0){ - if(devise == 1){ - comptes(id) += montantdeposer - } - if(devise==2){ - comptes(id)+=0.95*montantdeposer - } - } - printf("Votre depot a été pris en compte, le nouveau montant disponible sur votre compte est : %.2f CHF\n", comptes(id)) - } + while (montantderetrait>0){ + println("il reste "+ montantderetrait+ " "+ deviseprint+ " à distribuer" ) + println("Vous pouvez obtenir au maximum "+ math.ceil(montantderetrait/coupuresList(i)).toInt + " billet(s) de " + coupuresList(i)+" " + deviseprint) + println("Tapez o pour ok ou une autre valeur inférieure à celle proposée >") + check = readLine() + if(check =="o"){ + coupurescount+=((montantderetrait/coupuresList(i)).floor).toInt + montantderetrait-= math.ceil(montantderetrait/coupuresList(i)).toInt * coupuresList(i) + - def changepin(id : Int, codespin : Array[String]) : Unit={ - var newpin = "" - printf("Entrez votre nouveau pin") - codespin(id-1) = readLine() - } -} \ No newline at end of file + }else{ + montantderetrait-= check.toInt * coupuresList(i) + coupurescount+=check.toInt + } + i+=1 + } + println("Veuillez retirer la somme demandée") + + while (k!=coupurescount.length){ + println(coupurescount(k)+" billet(s) de " +coupuresList(small) + " " + deviseprint) + small+=1 + k+=1 + } + continuer= false + } + + } + if( choix == 4){ + println("Fin des opérations.n'oubliez pas de récupérer votre carte.") + } + } +} \ No newline at end of file diff --git a/bancomat2.scala b/bancomat2.scala new file mode 100644 index 0000000..562a1c5 --- /dev/null +++ b/bancomat2.scala @@ -0,0 +1,124 @@ +import scala.io.StdIn._ +object Main{ + def main(args: Array[String]): Unit = { + var pincorrect = Array("a","b","c","d","e") + var pin="" + var continuer = true + var montantinitial = 1200.0 + + var comptes= Array(montantinitial,montantinitial,montantinitial,montantinitial,montantinitial) + var nbclient = comptes.length + var check = 0 + + var tentative = 0 + var choix = 0 + var monID = 0 + + println("Saisissez votre code identifiant >") + monID = readLine().toInt + + + while(monID>nbclient){ + println("Cet identifiant n'est pas valable.") + println("Saisissez votre code identifiant >") + monID = readLine().toInt + + } + //demander a l'utilisateu le pin + println("Saisissez votre code pin > ") + pin = readLine("quel est votre pin? >") + if(pin == pincorrect(monID-1)){ + //afficher les operation + //demander a l'utilisateu de choisir une operation + println("Code correct !") + }else { + while (tentative < 3&&pin!=pincorrect) { + + println("Il faut saisir un pin correct > ") + pin = readLine() + tentative += 1 + println("Code pin erroné, il vous reste " + tentative + " tentatives >") + } + } + if(tentative==3 && pin!=pincorrect){ + println("Trop d'erreurs, abandon de l'identification") + } + while(continuer){ + //afficher les operation + println("Choisissez votre opération:") + println("1. Dépôt") + println("2. Consultation") + println("3. Retrait") + println("4. Changement du pin") + println("5. Terminer") + println("Entrez le numéro de l'opération: ") + choix = readLine().toInt + + if(choix == 1 ){ + depot(monID, comptes) + } + if (choix == 2) {printf("la valeur de montantdisponible : %.2f \n", comptes(monID) )} + if(choix == 3 ){ // si le client veut retirer de l'argent + retrait(monID, comptes) + continuer =false + } + if(choix ==4 ){ + changepin(monID, pincorrect) + } + if(choix ==5 ){ + println("Fin des opérations, n'oubliez pas de récupérer votre carte.") + } + } + } + + + def retrait(id : Int, comptes: Array[Double]) : Unit={ + var devise = 0 + var montantderetrait = 0 + var coupures = 0 + var correct =true + + println("quelle est la devise: 1 pour CHF et 2 pour EUR? ") + devise = readLine().toInt + println("quelle est le montant a retirer?") + montantderetrait = readLine().toInt + + if(montantderetrait %10 == 0){ + if(devise== 1){ + println("choisissez la coupure: 1 pour petite et 2 pour grande") + coupures = readInt() + } + comptes(id)-= montantderetrait*1.05 + printf("Votre retrait a été pris en compte, le nouveau montant disponible sur votre compte est : %.2f CHF\n", comptes(id)) + + } + else{println("operation impossible")} + } + + + def depot(id :Int, comptes : Array[Double]): Unit={ + var devise = 0 + var montantdeposer = 0 + + println("quelle est la devise: 1 pour CHF et 2 pour EUR? ") + devise = readInt() + println("quelle est le montant a deposer?") + montantdeposer = readInt() + if(montantdeposer %10 == 0){ + if(devise == 1){ + comptes(id) += montantdeposer + } + if(devise==2){ + comptes(id)+=0.95*montantdeposer + } + } + printf("Votre depot a été pris en compte, le nouveau montant disponible sur votre compte est : %.2f CHF\n", comptes(id)) + } + + + def changepin(id : Int, codespin : Array[String]) : Unit={ + var newpin = "" + printf("Entrez votre nouveau pin") + codespin(id-1) = readLine() + } +} \ No newline at end of file -- GitLab