Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import io.StdIn
- import scala.collection.mutable.ArrayBuffer
- object paiement {
- def main(args: Array[String]): Unit = {
- var choixZone = ""
- var choixPaiement = ""
- var demiTarif = ""
- var demi = ""
- var zoneChoisie = ""
- var sommeDue = 0d
- var nbTicketPlein = 0
- var nbTicketDemi = 0
- var prixTotal = 0d
- var paiement = 0
- var monnaieDonne = 0d
- val zoneA = 3
- val zoneB = 4
- val zoneC = 5
- val resultat = 0d
- var pieces = Array( 1, 2, 5, 10, 20, 50)
- var monnaie = ArrayBuffer[BigDecimal]()
- do {
- println("Choisir la zone souhaitée :\n a : Zone centre, b : Zone centre étendu, c : Zone agglomération")
- choixZone = StdIn.readLine() //on demande à l'utilisateur de choisir la zone
- } while (!(choixZone == "a" || choixZone == "b" || choixZone == "c")) //on demande que a,b,c et rien d'autre (pour éviter d'avoir autre chose)
- do {
- println("Avez-vous un demi-tarif? (oui/non)")
- demiTarif = StdIn.readLine() //on veut soit oui soit non et rien d'autre
- } while (!(demiTarif == "oui" || demiTarif == "non"))
- println("Entrez le nombre de tickets tarif plein souhaité:") //le tarif plein est la d'office donc on va juste regarder si la personne
- nbTicketPlein = StdIn.readInt() //a le demis-tarif
- demi = "Tarif plein"
- if (demiTarif == "oui") {
- println("Entrez le nombre de tickets demi-tarif souhaité:")
- nbTicketDemi = StdIn.readInt()
- demi = "Demi-tarif"
- }
- if (choixZone == "a") { //calculer le prix selon la zone choisie
- prixTotal = zoneA * (nbTicketPlein + nbTicketDemi/2)
- zoneChoisie = "Zone centre"
- } else if (choixZone == "b") {
- prixTotal = zoneB * (nbTicketPlein + nbTicketDemi/2)
- zoneChoisie = "Zone centre étendue"
- } else if (choixZone == "c") {
- prixTotal = zoneC * (nbTicketPlein + nbTicketDemi/2)
- zoneChoisie = "Zone agglomération"
- }
- do{
- println("Il vous reste " + prixTotal + " à payer \n pièces autorisées : \n 5, 2, 1 Francs, 50, 20 et 10 Centimes\n")
- paiement = StdIn.readInt()
- monnaie += paiement
- if (paiement == 1 || paiement == 2 || paiement == 5 ) {
- prixTotal = -paiement
- } else if (paiement == 10 || paiement == 20 || paiement == 50 ){
- prixTotal = -(paiement/100)
- } else println("Cette pièce n'existe pas")
- } while (prixTotal>0)
- val reste = -prixTotal
- do{
- println("Voulez vous confirmer l'achat? (oui/non)")
- choixPaiement = StdIn.readLine()
- } while (!(choixPaiement == "oui" || choixPaiement == "non"))
- if (choixPaiement == "oui"){
- for ( i <- 0 to (nbTicketPlein + nbTicketDemi))
- println("unireso-tps.\n" + zoneChoisie + ".\n"+ demi + ".\n" + "Montant:" + sommeDue + ".\n")
- } else if (choixPaiement == "non"){
- println("Voici votre monnaie: \n" + monnaie.mkString( "chf \n" ) + "chf")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement