galinyotsev123

ProgBasicsExam3and4November2018-E04weddingDecoration

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