Advertisement
Rayk

Inventory

Jul 13th, 2020
1,278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. package Test;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class Third {
  8.     public static void main(String[] args) {
  9.         Scanner scan = new Scanner(System.in);
  10.         String[] tokens = scan.nextLine().split(", ");
  11.         List<String> journal = new ArrayList<>();
  12.         for (int i = 0; i < tokens.length; i++) {
  13.  
  14.             journal.add(tokens[i]);
  15.         }
  16.         String input = scan.nextLine();
  17.         while (!"Craft!".equals(input)){
  18.             tokens = input.split(" - ");
  19.             if (tokens[0].equals("Collect")){
  20.                 if (!journal.contains(tokens[1])){
  21.                     journal.add(tokens[1]);
  22.                 }
  23.             }else if (tokens[0].equals("Drop")){
  24.                 if (journal.contains(tokens[1])){
  25.                     journal.remove(tokens[1]);
  26.                 }
  27.             }else if (tokens[0].equals("Combine Items")){
  28.                 String[] command = tokens[1].split("\\:");
  29.                 if (journal.contains(command[0])){
  30.                     int index = journal.indexOf(command[0]);
  31.                     journal.add(index + 1, command[1]);
  32.                 }
  33.             }else if (tokens[0].equals("Renew")){
  34.                 if (journal.contains(tokens[1])){
  35.                     journal.remove(tokens[1]);
  36.                     journal.add(tokens[1]);
  37.                 }
  38.             }
  39.             input = scan.nextLine();
  40.         }
  41.         System.out.println(String.join(", ", journal));
  42.  
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement