SHARE
TWEET

Easter Gifts

a guest Jun 24th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. public class easterGifts {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.         Scanner sc = new Scanner (System.in);
  10.         String[] input = sc.nextLine().split(" +");
  11.         String command = sc.nextLine();
  12.         List<String> gifts = new ArrayList<>();
  13.         for (String string : input) {
  14.             gifts.add(string);
  15.         }
  16.        
  17.         while(!command.equals("No Money")) {
  18.             String[] tokens = command.split(" +");
  19.             switch (tokens[0]) {
  20.                 case "OutOfStock" : if (gifts.contains(tokens[1])) {
  21.                        
  22.                         String outOfStockGift = "None";
  23.                         for (String string : tokens) {
  24.                             gifts.set(gifts.indexOf(tokens[1]), outOfStockGift);
  25.                         }
  26.                 }break;
  27.                 case "Required" : int index = Integer.parseInt(tokens[2]);
  28.                     if (index >= 0 && index < gifts.size()) {
  29.                         gifts.set(index, tokens[1]);
  30.                 } break;
  31.                 case "JustInCase" : gifts.set(gifts.size()-1, tokens[1]); break;
  32.             }
  33.             command = sc.nextLine();
  34.         }
  35.         for (String string : gifts) {
  36.             if (!string.equals("None")) {
  37.             System.out.print(string+" ");
  38.             }
  39.         }
  40.     }
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top