Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package caixer_automatic;
- import java.util.Scanner;
- /**
- *
- * @author Sergio
- */
- public class Caixer_Automatic {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- int c, b50, b20, resto;
- //Petición de la cantidad a retirar
- Scanner teclado =new Scanner(System.in);
- System.out.println("Introdueix la quantitat demanada en eur.");
- int cantidadPedida=teclado.nextInt();
- c=cantidadPedida;
- System.out.println("Has demanat "+cantidadPedida+" eur.");
- //Cálculo de los billetes a devolver. Primera iteración
- b50=c/50;
- resto=c%50;
- b20=resto/20;
- //Primera iteración finalizada. Comprobamos si resto=0.
- if(c==b50*50+b20*20)
- {
- if(b20!=0&&b50!=0)System.out.println(+b50+" bitllets de 50\n"+b20+" bitllets de 20");
- if(b20!=0&&b50==0)System.out.println(+b20+" bitllet/s de 20");
- if(b20==0&&b50!=0)System.out.println(+b50+" bitllet/s de 50");
- }
- //Iniciamos Segunda iteración.
- else if(resto>=10)
- {
- b50=b50-1;
- if(b50<0)b50=0;
- b20=(resto+50)/20;
- //Segunda iteración finalizada. Comprobamos si resto=0.
- if(c==b50*50+b20*20)
- {
- if(b20!=0&&b50!=0)System.out.println(+b50+" bitllets de 50\n"+b20+" bitllets de 20");
- if(b20!=0&&b50==0)System.out.println(+b20+" bitllet/s de 20");
- if(b20==0&&b50!=0)System.out.println(+b50+" bitllet/s de 50");
- }
- else
- {
- System.out.println("No es pot lliurar la quantiat demanada"
- + "\nAquest caixer només disposa de bitllets de 20 i 50");
- }
- }
- else
- {
- System.out.println("No es pot lliurar la quantitat demanada"
- + "\nAquest caixer només disposa de bitllets de 20 i 50");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement