galinyotsev123

ProgBasicsExam28and29July2018-E05fanShop

Dec 28th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class E05fanShop {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int budget = Integer.parseInt(scanner.nextLine());
  8. int n = Integer.parseInt(scanner.nextLine());
  9.  
  10. int sum = 0;
  11.  
  12. for (int i = 1; i <= n; i++) {
  13. String item = scanner.nextLine();
  14. int price = 0;
  15. if (item.equalsIgnoreCase("hoodie")) {
  16. price = 30;
  17. } else if (item.equalsIgnoreCase("keychain")) {
  18. price = 4;
  19. } else if (item.equalsIgnoreCase("T-shirt")) {
  20. price = 20;
  21. } else if (item.equalsIgnoreCase("flag"))
  22. {
  23. price = 15;
  24. }
  25.  
  26. else if (item.equalsIgnoreCase("sticker"))
  27. {
  28. price = 1;
  29. }
  30. sum += price;
  31. }
  32.  
  33. int diff =Math.abs(sum - budget);
  34.  
  35. if (budget >= sum) {
  36. System.out.printf("You bought %d items and left with %d lv.", n, diff);
  37. }
  38. else {
  39. System.out.printf("Not enough money, you need %d more lv.", diff);
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment