Advertisement
Todorov99

Untitled

Dec 14th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Test {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner input = new Scanner(System.in);
  8.  
  9. double money = Double.parseDouble(input.next());
  10. String command = input.next();
  11.  
  12. int count = 0;
  13. int boughtProducts = 0;
  14. double sum = 0;
  15. double price = 0;
  16.  
  17. while (true){
  18.  
  19. if(command.equals("Finish")){
  20. break;
  21. }
  22.  
  23.  
  24. switch (command){
  25. case "Star":
  26.  
  27. if(count == 2){
  28. price = 5.69 - 5.69 * 0.3;
  29. money -= price;
  30. count = 0;
  31. }else {
  32. price = 5.69;
  33. money -= price;
  34. count++;
  35. }
  36.  
  37. boughtProducts++;
  38.  
  39. break;
  40. case "Angel":
  41. if(count == 2){
  42. price = 8.49 - 8.49 * 0.3;
  43. money -= price;
  44. count = 0;
  45. }else {
  46.  
  47. price = 8.49;
  48. money -= 8.49;
  49. count++;
  50. }
  51.  
  52. boughtProducts++;
  53.  
  54. break;
  55. case "Lights":
  56.  
  57. if(count == 2){
  58. price = 11.20 - 11.20 * 0.3;
  59. money -= price;
  60. count = 0;
  61. }else {
  62. price = 11.20;
  63. money -= 11.20;
  64. count++;
  65. }
  66.  
  67. boughtProducts++;
  68.  
  69.  
  70. break;
  71. case "Wreath":
  72. if(count == 2){
  73. price = 15.50 - 15.50 * 0.3;
  74. money -= price;
  75. count = 0;
  76. }else {
  77. price = 15.50;
  78. money -= price;
  79. count++;
  80. }
  81.  
  82. boughtProducts++;
  83.  
  84. break;
  85. case "Candle":
  86. if(count == 2){
  87.  
  88. price = 3.59 - 3.59 * 0.3;
  89. money -= price;
  90. count = 0;
  91. }else {
  92. price = 3.59;
  93. money -= price;
  94. count++;
  95. }
  96.  
  97. boughtProducts++;
  98.  
  99. break;
  100.  
  101. }
  102.  
  103. if(money > 0){
  104. sum += price;
  105. }else {
  106. break;
  107. }
  108.  
  109.  
  110. command = input.next();
  111. }
  112.  
  113. if(money < 0){
  114. System.out.format("Not enough money! You need %.2flv more.\n", Math.abs(money));
  115. System.out.printf("%d items -> %.2flv spent.", boughtProducts - 1, sum);
  116. }else {
  117. System.out.printf("Congratulations! You bought everything!\n");
  118. System.out.printf("%d items -> %.2flv spent.", boughtProducts, sum);
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement