Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MidExam.O5;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- public class O3Inventory {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- List<String> items = new ArrayList<>(Arrays.asList(scan.nextLine().split(", ")));
- String command = scan.nextLine();
- while (!command.equals("Craft!")) {
- String[] tokens = command.split(" - ");
- if (tokens[0].equals("Collect")) {
- if (items.contains(tokens[1])) {
- } else {
- String collectItem = tokens[1];
- items.add(collectItem);
- }
- } else if (tokens[0].equals("Drop")) {
- if (items.contains(tokens[1])) {
- items.remove(tokens[1]);
- } else {
- }
- } else if (tokens[0].equals("Combine Items")) {
- String[] item = tokens[1].split(":");
- String oldItem = item[0];
- String newItem = item[1];
- for (int i = 0; i < items.size(); i++) {
- String currentItem = items.get(i);
- if (currentItem.equals(oldItem)) {
- items.add(i + 1, newItem);
- break;
- }
- }
- } else if (tokens[0].equals("Renew")) {
- if (items.contains(tokens[1])) {
- String renewItem = tokens[1];
- items.remove(tokens[1]);
- items.add(renewItem);
- }
- }
- command = scan.nextLine();
- }
- for (int i = 0; i <= items.size() - 1; i++) {
- if (i != items.size() - 1) {
- System.out.printf("%s, ", items.get(i));
- } else if (i == items.size() - 1) {
- System.out.printf("%s ", items.get(i));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment