Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Demo;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.List;
- public class Inventory {
- public static void main(String[] args) throws IOException {
- BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
- List<String> items = new ArrayList<>(List.of(scanner.readLine().split(", ")));
- String command;
- while (!"Craft!".equals(command = scanner.readLine())) {
- String[] tokens = command.split("\\s-\\s");
- if (tokens[0].equals("Collect")) {
- if (!items.contains(tokens[1])) {
- items.add(tokens[1]);
- }
- } else if (tokens[0].equals("Drop")) {
- items.remove(tokens[1]);
- } else if (tokens[0].equals("Combine Items")) {
- String[] oldAndNew = tokens[1].split(":");
- if (items.contains(oldAndNew[0])) {
- int index = items.indexOf(oldAndNew[0]) + 1;
- items.add(index, oldAndNew[1]);
- }
- } else if (tokens[0].equals("Renew")) {
- if (items.contains(tokens[1])) {
- items.remove(tokens[1]);
- items.add(tokens[1]);
- }
- }
- }
- System.out.println(String.join(", ", items));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment