Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Decoration {
  3. public static void main(String[] args) {
  4. Scanner scanner = new Scanner(System.in);
  5.  
  6. boolean stopped = false;
  7. double budget = Double.parseDouble(scanner.nextLine());
  8.  
  9.  
  10. double priceBalloonsTotal = 0;
  11. double priceFlowersTotal = 0;
  12. double priceCandlesTotal = 0;
  13. double priceRibbonsTotal = 0;
  14.  
  15. int totalBalloonsCount = 0;
  16. int totalCandlesCount = 0;
  17. int totalFlowersCount = 0;
  18. int totalRibbonsMeters = 0;
  19.  
  20.  
  21. while (budget > 0) {
  22. String command = scanner.nextLine();
  23.  
  24. if (command.equals("balloons")) {
  25. int balloonsCount = Integer.parseInt(scanner.nextLine());
  26. totalBalloonsCount += balloonsCount;
  27. priceBalloonsTotal += (0.1 * balloonsCount);
  28. budget -= (0.1 * balloonsCount);
  29. } else if (command.equals("flowers")) {
  30. int flowersCount = Integer.parseInt(scanner.nextLine());
  31. totalFlowersCount += flowersCount;
  32. priceFlowersTotal += (1.5 * flowersCount);
  33. budget -= (1.5 * flowersCount);
  34. } else if (command.equals("candles")) {
  35. int candlesCount = Integer.parseInt(scanner.nextLine());
  36. totalCandlesCount += candlesCount;
  37. priceCandlesTotal += (0.5 * candlesCount);
  38. budget -= (0.5 * candlesCount);
  39. }else if (command.equals("ribbon")) {
  40. int ribbonMeters = Integer.parseInt(scanner.nextLine());
  41. totalRibbonsMeters += ribbonMeters;
  42. priceRibbonsTotal += (2 * ribbonMeters);
  43. budget -= (2 * ribbonMeters);
  44. }
  45.  
  46. if (command.equals("stop")) {
  47. System.out.printf("Spend money: %.2f\n", priceBalloonsTotal + priceCandlesTotal + priceFlowersTotal + priceRibbonsTotal);
  48. System.out.printf("Money left: %.2f\n", budget);
  49. stopped = true;
  50. break;
  51. }
  52. }
  53. if(!stopped)
  54. {
  55. System.out.println("All money is spent!");
  56. }
  57.  
  58. System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.", totalBalloonsCount,
  59. totalRibbonsMeters, totalFlowersCount, totalCandlesCount);
  60. stopped = false;
  61. }
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement