Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Algorithmie
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mathias.catala
Algorithmie
Commits
6dbbe2a1
Commit
6dbbe2a1
authored
1 year ago
by
mathias.catala
Browse files
Options
Downloads
Patches
Plain Diff
"update"
parent
aeec1ef4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bancomat.scala
+161
-110
161 additions, 110 deletions
bancomat.scala
bancomat2.scala
+124
-0
124 additions, 0 deletions
bancomat2.scala
with
285 additions
and
110 deletions
bancomat.scala
+
161
−
110
View file @
6dbbe2a1
import
scala.io.StdIn._
import
scala.io.StdIn._
import
scala.collection.mutable.ArrayBuffer
object
Main
{
object
Main
{
var
continuer
=
true
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
var
pincorrect
=
Array
(
"a"
,
"b"
,
"c"
,
"d"
,
"e"
)
var
pincorrect
=
"f"
var
pin
=
""
var
pin
=
""
var
continuer
=
true
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
tentative
=
0
var
choix
=
0
var
depot
=
0
var
monID
=
0
var
consultation
=
0
var
montantdeposer
=
0
println
(
"Saisissez votre code identifiant >"
)
var
devise
=
0
monID
=
readLine
().
toInt
var
choix
=
0
var
montantderetrait
=
0.0
var
coupures
=
0
while
(
monID
>
nbclient
){
var
montantdisponible
=
1200.0
;
println
(
"Cet identifiant n'est pas valable."
)
println
(
"Saisissez votre code identifiant >"
)
monID
=
readLine
().
toInt
while
(
continuer
)
{
}
//demander a l'utilisateu le pin
//demander a l'utilisateu le pin
println
(
"Saisissez votre code pin > "
)
println
(
"Saisissez votre code pin > "
)
pin
=
readLine
(
"quel est votre pin? >"
)
pin
=
readLine
()
if
(
pin
==
pincorrect
(
monID
-
1
)
){
if
(
pin
==
pincorrect
){
//afficher les operation
//afficher les operation
//demander a l'utilisateu de choisir une operation
//demander a l'utilisateu de choisir une operation
println
(
"Code correct !"
)
println
(
"Choisissez votre opération:"
)
}
else
{
println
(
"1. Dépôt"
)
while
(
tentative
<
3
&&
pin
!=
pincorrect
)
{
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
()
if
(
choix
==
1
){
tentative
+=
1
continuer
=
true
println
(
"Code pin erroné, il vous reste "
+
tentative
+
" tentatives >"
)
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
){
if
(
choix
==
2
)
{
println
(
"choisissez la coupure: 1 pour petite et 2 pour grande"
)
printf
(
"la valeur de montantdisponible : %.2f \n"
,
montantdisponible
)
coupures
=
readInt
()
}
}
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
={
if
(
coupures
==
2
){
var
devise
=
0
i
=
0
var
montantdeposer
=
0
}
else
if
(
coupures
==
1
||
devise
==
2
)
{
i
=
2
small
=
2
}
println
(
"quelle est la devise: 1 pour CHF et 2 pour EUR? "
)
while
(
montantderetrait
>
0
){
devise
=
readInt
()
println
(
"il reste "
+
montantderetrait
+
" "
+
deviseprint
+
" à distribuer"
)
println
(
"quelle est le montant a deposer?"
)
println
(
"Vous pouvez obtenir au maximum "
+
math
.
ceil
(
montantderetrait
/
coupuresList
(
i
)).
toInt
+
" billet(s) de "
+
coupuresList
(
i
)+
" "
+
deviseprint
)
montantdeposer
=
readInt
()
println
(
"Tapez o pour ok ou une autre valeur inférieure à celle proposée >"
)
if
(
montantdeposer
%
10
==
0
){
check
=
readLine
()
if
(
devise
==
1
){
if
(
check
==
"o"
){
comptes
(
id
)
+=
montantdeposer
coupurescount
+=((
montantderetrait
/
coupuresList
(
i
)).
floor
).
toInt
}
montantderetrait
-=
math
.
ceil
(
montantderetrait
/
coupuresList
(
i
)).
toInt
*
coupuresList
(
i
)
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
={
}
else
{
var
newpin
=
""
montantderetrait
-=
check
.
toInt
*
coupuresList
(
i
)
printf
(
"Entrez votre nouveau pin"
)
coupurescount
+=
check
.
toInt
codespin
(
id
-
1
)
=
readLine
()
}
}
i
+=
1
}
}
\ No newline at end of file
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
This diff is collapsed.
Click to expand it.
bancomat2.scala
0 → 100644
+
124
−
0
View file @
6dbbe2a1
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment