Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.Array;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class Inventory {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<String> journal = Arrays.stream(scanner.nextLine().split(", ")).collect(Collectors.toList());
- String commands = scanner.nextLine();
- while (!commands.equals("Craft!")) {
- String[] command = commands.split(" - ");
- if (command[0].equals("Collect")) {
- String item = command[1];
- boolean isExist = false;
- for (int i = 0; i < journal.size(); i++) {
- if (journal.get(i).equals(item)) {
- isExist = true;
- break;
- }
- }
- if (isExist == false) {
- journal.add(item);
- }
- } else if (command[0].equals("Drop")) {
- String itemForRemove = command[1];
- boolean isExist = false;
- for (int i = 0; i < journal.size(); i++) {
- if (journal.get(i).contains(itemForRemove)) {
- journal.remove((i));
- break;
- }
- }
- } else if (command[0].contains("Combine Items")) {
- String [] oldAndNew = command[1].split(":");
- String oldItem = oldAndNew[0];
- String newItem = oldAndNew[1];
- for (int i = 0; i <journal.size() ; i++) {
- if(journal.get(i).contains(oldItem)){
- journal.add(i+1,newItem);
- break;
- }
- }
- } else if (command[0].equals("Renew")) {
- String item = command[1];
- for (int i = 0; i <journal.size(); i++) {
- if(journal.get(i).equals(item)){
- journal.remove(i);
- journal.add(item);
- break;
- }
- }
- }
- commands = scanner.nextLine();
- }
- String result = String.join(", ",journal);
- System.out.println(result.trim());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement