Bandor

Untitled

Nov 15th, 2019
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package caixer_automatic;
  7. import java.util.Scanner;
  8. /**
  9.  *
  10.  * @author Sergio
  11.  */
  12. public class Caixer_Automatic {
  13.  
  14.     /**
  15.      * @param args the command line arguments
  16.      */
  17.     public static void main(String[] args) {
  18.         int c, b50, b20, resto;
  19.     //Petición de la cantidad a retirar    
  20.         Scanner teclado =new Scanner(System.in);
  21.         System.out.println("Introdueix la quantitat demanada en eur.");
  22.         int cantidadPedida=teclado.nextInt();
  23.         c=cantidadPedida;
  24.         System.out.println("Has demanat "+cantidadPedida+" eur.");
  25.     //Cálculo de los billetes a devolver. Primera iteración
  26.         b50=c/50;
  27.         resto=c%50;
  28.         b20=resto/20;
  29.     //Primera iteración finalizada. Comprobamos si resto=0.
  30.         if(c==b50*50+b20*20)
  31.         {
  32.           if(b20!=0&&b50!=0)System.out.println(+b50+" bitllets de 50\n"+b20+" bitllets de 20");
  33.           if(b20!=0&&b50==0)System.out.println(+b20+" bitllet/s de 20");
  34.           if(b20==0&&b50!=0)System.out.println(+b50+" bitllet/s de 50");
  35.         }
  36.     //Iniciamos Segunda iteración.
  37.         else if(resto>=10)
  38.         {
  39.             b50=b50-1;
  40.             if(b50<0)b50=0;
  41.             b20=(resto+50)/20;
  42.     //Segunda iteración finalizada. Comprobamos si resto=0.
  43.             if(c==b50*50+b20*20)
  44.             {
  45.               if(b20!=0&&b50!=0)System.out.println(+b50+" bitllets de 50\n"+b20+" bitllets de 20");
  46.               if(b20!=0&&b50==0)System.out.println(+b20+" bitllet/s de 20");
  47.               if(b20==0&&b50!=0)System.out.println(+b50+" bitllet/s de 50");
  48.             }
  49.             else
  50.             {
  51.               System.out.println("No es pot lliurar la quantiat demanada"
  52.               + "\nAquest caixer només disposa de bitllets de 20 i 50");
  53.             }  
  54.        }
  55.        else
  56.        {
  57.          System.out.println("No es pot lliurar la quantitat demanada"
  58.          + "\nAquest caixer només disposa de bitllets de 20 i 50");
  59.        }
  60.     }
  61. }
Add Comment
Please, Sign In to add comment