Advertisement
Guest User

projet pika

a guest
Nov 13th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 3.32 KB | None | 0 0
  1. import io.StdIn
  2. import scala.collection.mutable.ArrayBuffer
  3.  
  4. object paiement {
  5.   def main(args: Array[String]): Unit = {
  6.  
  7.     var choixZone = ""
  8.     var choixPaiement = ""
  9.     var demiTarif = ""
  10.     var demi = ""
  11.     var zoneChoisie = ""
  12.     var sommeDue = 0d
  13.     var nbTicketPlein = 0
  14.     var nbTicketDemi = 0
  15.     var prixTotal = 0d
  16.     var paiement = 0
  17.     var monnaieDonne = 0d
  18.     val zoneA = 3
  19.     val zoneB = 4
  20.     val zoneC = 5
  21.     val resultat = 0d
  22.     var pieces = Array( 1, 2, 5, 10, 20, 50)
  23.     var monnaie = ArrayBuffer[BigDecimal]()
  24.  
  25.  
  26.     do {
  27.       println("Choisir la zone souhaitée :\n a : Zone centre, b : Zone centre étendu, c : Zone agglomération")
  28.       choixZone = StdIn.readLine()                                                        //on demande à l'utilisateur de choisir la zone
  29.  
  30.     } while (!(choixZone == "a" || choixZone == "b" || choixZone == "c"))                 //on demande que a,b,c et rien d'autre (pour éviter d'avoir autre chose)
  31.     do {
  32.       println("Avez-vous un demi-tarif? (oui/non)")
  33.       demiTarif = StdIn.readLine()                                                        //on veut soit oui soit non et rien d'autre
  34.  
  35.     } while (!(demiTarif == "oui" || demiTarif == "non"))        
  36.  
  37.     println("Entrez le nombre de tickets tarif plein souhaité:")                          //le tarif plein est la d'office donc on va juste regarder si la personne
  38.     nbTicketPlein = StdIn.readInt()                                                       //a le demis-tarif
  39.     demi = "Tarif plein"
  40.    
  41.     if (demiTarif == "oui") {                                                              
  42.       println("Entrez le nombre de tickets demi-tarif souhaité:")
  43.       nbTicketDemi = StdIn.readInt()
  44.       demi = "Demi-tarif"
  45.  
  46.     }
  47.     if (choixZone == "a") {                                                              //calculer le prix selon la zone choisie
  48.       prixTotal = zoneA * (nbTicketPlein + nbTicketDemi/2)
  49.       zoneChoisie = "Zone centre"
  50.     } else if (choixZone == "b") {
  51.       prixTotal = zoneB * (nbTicketPlein + nbTicketDemi/2)
  52.       zoneChoisie = "Zone centre étendue"
  53.     } else if (choixZone == "c") {
  54.       prixTotal = zoneC * (nbTicketPlein + nbTicketDemi/2)
  55.       zoneChoisie = "Zone agglomération"
  56.     }
  57.    
  58.     do{
  59.       println("Il vous reste " + prixTotal + " à payer \n pièces autorisées : \n 5, 2, 1 Francs, 50, 20 et 10 Centimes\n")
  60.       paiement = StdIn.readInt()
  61.       monnaie += paiement
  62.        if (paiement == 1 || paiement == 2 ||  paiement == 5 ) {
  63.          prixTotal = -paiement
  64.        } else if (paiement == 10 || paiement == 20 || paiement == 50 ){
  65.          prixTotal = -(paiement/100)
  66.        } else println("Cette pièce n'existe pas")
  67.        
  68.      } while (prixTotal>0)
  69.          val reste = -prixTotal
  70.          
  71.      do{
  72.        println("Voulez vous confirmer l'achat? (oui/non)")
  73.        choixPaiement = StdIn.readLine()
  74.      } while (!(choixPaiement == "oui" || choixPaiement == "non"))
  75.  
  76.       if (choixPaiement == "oui"){
  77.         for ( i <- 0 to (nbTicketPlein + nbTicketDemi))
  78.         println("unireso-tps.\n" + zoneChoisie + ".\n"+ demi + ".\n" + "Montant:" + sommeDue + ".\n")
  79.       } else if (choixPaiement == "non"){
  80.         println("Voici votre monnaie: \n" + monnaie.mkString( "chf \n" ) + "chf")
  81.       }
  82.       }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement