aneliyanestorova

calculate_change

Mar 28th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class CalculateChange {
  3. public static void main(String[] args) {
  4.  
  5.  
  6. Scanner scanner = new Scanner(System.in);
  7. double price, provided, change;
  8.  
  9. //System.out.print("Enter the purchase price:");
  10. price = Double.parseDouble(scanner.nextLine()) * 100;
  11. //System.out.print("Enter the amount given by the customer:");
  12. provided = Double.parseDouble(scanner.nextLine()) * 100;
  13. if (provided > price) {
  14.  
  15. change = provided - price;
  16.  
  17.  
  18.  
  19. double ones = change / 100;
  20. if (ones > 0) {
  21. change = change % 100;
  22. System.out.println(Math.floor(ones) + "x 1 lev");
  23. }
  24. double fifty = change / 50;
  25. if (fifty > 0) {
  26. change = change % 50;
  27. System.out.println(Math.floor(fifty) + " x 50 stotinki");
  28. }
  29. double twenty = change / 20;
  30. if (twenty > 0) {
  31. change = change % 20;
  32. System.out.println(Math.floor(twenty) + " x 20 stotinki");
  33. }
  34. double ten = change / 10;
  35. if (ten > 0) {
  36. change = change % 10;
  37. System.out.println(Math.floor(ten) + " x 10 stotinki");
  38. }
  39. double five = change / 5;
  40. if (five > 0) {
  41. change = change % 5;
  42. System.out.println(Math.floor(five) + " x 5 stotinki");
  43. }
  44. double two = change / 2;
  45. if (five > 0) {
  46. change = change % 2;
  47. System.out.println(Math.floor(two) + " x 2 stotinki");
  48. }
  49. double one = change;
  50. if (one > 0) {
  51. change = change % 1;
  52. System.out.println(Math.floor(one) + " x 1 stotinka");
  53. }
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment