Advertisement
yovkovbpfps

EXAM 28-29 JULY 05.FAN SHOP

May 3rd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FanShop {
  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.equals("hoodie")) {
  16. price = 30;
  17. } else if (item.equals("keychain")) {
  18. price = 4;
  19. } else if (item.equals("T-shirt")) {
  20. price = 20;
  21. } else if (item.equals("flag")) {
  22. price = 15;
  23. } else {
  24. price = 1;
  25. }
  26. sum += price;
  27. }
  28.  
  29. int diff = Math.abs(sum - budget);
  30.  
  31. if (budget >= sum) {
  32. System.out.printf("You bought %d items and left with %d lv.", n, diff);
  33. } else {
  34. System.out.printf("Not enough money, you need %d more lv.", diff);
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement