Advertisement
Krassi_Daskalova

EasterGifts

Jun 29th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6. public class EasterGifts2 {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. String[] input = scanner.nextLine().split(" ");
  11. List<String> gifts = new ArrayList<>(Arrays.asList(input));
  12.  
  13. String command = scanner.nextLine();
  14. while (!command.equals("No Money")) {
  15. String[] com = command.split(" ");
  16. String differentCommand = com[0];
  17.  
  18. if (differentCommand.equals("OutOfStock")) {
  19. for (String gift : gifts) {
  20. int index = gifts.indexOf(com[1]);
  21. if (index >= 0 && index <= gifts.size()) {
  22. gifts.set(index, "None");
  23. }
  24. }
  25. } else if (differentCommand.equals("Required")) {
  26. String requiredGift = com[1];
  27. int index = Integer.parseInt(com[2]);
  28. if (index >= 0 && index <= gifts.size()) {
  29. gifts.set(index, requiredGift);
  30. }
  31. } else if (differentCommand.equals("JustInCase")) {
  32. int index = gifts.size() - 1;
  33. gifts.set(index, com[1]);
  34. }
  35. command = scanner.nextLine();
  36. }
  37. for (String gift : gifts) {
  38. if(!gift.equals("None")){
  39. System.out.print(gift + " ");
  40. }
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement