Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) throws IOException {
  8.  
  9. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  10.  
  11. double budget = Double.parseDouble(br.readLine());
  12. String product = br.readLine();
  13.  
  14. double spentMoney = 0;
  15. int productsCount = 0;
  16. int boughtProductsCount = 0;
  17.  
  18. while (!product.equals("Finish"))
  19. {
  20. double currentPrice = 0;
  21.  
  22. switch (product)
  23. {
  24. case "Star": currentPrice = 5.69; break;
  25. case "Angel": currentPrice = 8.49; break;
  26. case "Lights": currentPrice = 11.20; break;
  27. case "Wreath": currentPrice = 15.50; break;
  28. case "Candle": currentPrice = 3.59; break;
  29. }
  30.  
  31. if (currentPrice != 0)
  32. {
  33. ++productsCount;
  34.  
  35. if (productsCount % 3 == 0)
  36. {
  37. currentPrice *= 0.70;
  38. }
  39.  
  40. budget -= currentPrice;
  41.  
  42. if (budget < 0)
  43. {
  44. break;
  45. }
  46.  
  47. spentMoney += currentPrice;
  48. ++boughtProductsCount;
  49. }
  50.  
  51. product = br.readLine();
  52. }
  53.  
  54. if (budget < 0)
  55. {
  56. System.out.println(String.format("Not enough money! You need %.2flv more.", Math.abs(budget)));
  57. }
  58.  
  59. else
  60. {
  61. System.out.println("Congratulations! You bought everything!");
  62. }
  63.  
  64. System.out.println(String.format("%d items -> %.2flv spent.", boughtProductsCount, spentMoney));
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement