diff --git a/bancomat.scala b/bancomat.scala index 8c315d85656c7521d7dd8832e0c1ef124b3a287b..1b42255457f5e728b63883220fe02bdd490f25d3 100644 --- a/bancomat.scala +++ b/bancomat.scala @@ -1,142 +1,129 @@ import scala.io.StdIn._ object Main{ + + var continuer = true def main(args: Array[String]): Unit = { - var pincorrect = "INTRO1234" + var pincorrect = Array("a","b","c","d","e") var pin="" var continuer = true - var montantinitial = 1200.0 + 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 choixdevise1 = "CHF" - var choixdevise2 = "EUR" var choix = 0 - var depot = 0 - var choix1 = depot - var consultation = 0 - var choix2 = consultation - var montantdeposer = 0 - var devise=0 - var retrait = 0 - var choix3 = retrait - var montantderetrait = "" - var geossecoupures = 0 - var petitesecoupures = 0 - var coupures = 0 - var montantderetraitEuro = 0 - var montantautoriser = 1080 - var montantautoriserEuro = 0 - var montantdisponible = montantinitial - - - - while (continuer) - { - //afficher les operation - 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 - if(choix == 1 || choix == 2 || choix == 3 || choix == 4){ - continuer = false - } - if( choix == 4){ - println("Fin des opérations.n'oubliez pas de récupérer votre carte.") - } + var monID = 0 + + println("Saisissez votre code identifiant >") + monID = readLine().toInt - if(choix == 1 || choix == 2 || choix == 3 ){ - //demander a l'utilisateu le pin + + 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){ + if(pin == pincorrect(monID-1)){ //afficher les operation //demander a l'utilisateu de choisir une operation - 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 - } - else { - while (tentative < 3&&pin!=pincorrect) { + println("Code correct !") + }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 - } - } - - if(choix == 1 ){ - continuer= true - while(continuer){ - 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 !=1 || devise!=2|| montantdeposer %10 != 0 ) { - - println("operation impossible") + 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(devise== 1|| devise == 2){ - if(devise==1&&montantdeposer %10 == 0 ){ - println("operation reussie; "+"montantdisponible" + montantinitial + montantdeposer) - } - } else { - println("operation impossible") - } - if( devise==2&& montantdeposer %10 == 0){ - println ("montantdisponible " +montantinitial + 0.95*montantdeposer) - } - if(devise!=2|| montantdeposer %10 != 0) { - if(montantdeposer%10!=0||devise!=1) - println("operation impossible") - } - montantdisponible=montantinitial+montantdeposer - printf("Votre depot a été pris en compte, le nouveau montant disponible sur votre compte est : %.2f CHF\n", montantdisponible) - } - } - - - - if (choix == 2) { - printf("la valeur de montantdisponible : %.2f \n", montantdisponible ) - } - } - - - - - - - - - - - - - - - if( choix == 4){ - println("Fin des opérations.n'oubliez pas de récupérer votre carte.") - } - } -} \ No newline at end of file + 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