Advertisement
damesova

Fan shop - Java

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