Advertisement
Guest User

WizardPoker/Programming Fundamentals Mid Exam - 2 November 2

a guest
Dec 12th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.13 KB | None | 0 0
  1. package examsFundamentals.programmingFundamentalsMidExam_2November2019Group1;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import java.util.Scanner;
  7. import java.util.stream.Collectors;
  8.  
  9. public class WizardPoker03 {
  10.     public static void main(String[] args) {
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13.         List<String> cards = Arrays.
  14.                 stream(scanner.nextLine().
  15.                         split(":")).
  16.                 collect(Collectors.toList());
  17.         String line = scanner.nextLine();
  18.         while (!"Ready".equals(line)) {
  19.             String[] input = line.split("\\s+");
  20.             String command = input[0];
  21.             String card = input[1];
  22.             switch (command) {
  23.                 case "Add":
  24.                     if (!cards.contains(card)) {
  25.                         System.out.println("Card not found.");
  26.                  
  27.                     } else {
  28.                         cards.remove(card);
  29.                         cards.add(card);
  30.                     }
  31.                     break;
  32.                 case "Insert":
  33.                     int index = Integer.parseInt(input[2]);
  34.                     if (!cards.contains(card) && (index < 0 || index >= cards.size())) {
  35.                         System.out.println("Error!");
  36.  
  37.                     } else {
  38.                         cards.remove(card);
  39.                         cards.set(index, card);
  40.                     }
  41.                     break;
  42.                 case "Remove":
  43.                     if (!cards.contains(card)) {
  44.                         System.out.println("Card not found.");
  45.  
  46.                     } else {
  47.                         cards.remove(card);
  48.                     }
  49.                     break;
  50.                 case "Swap":
  51.                     String nameCard = input[2];
  52.                     Collections.swap(cards, cards.indexOf(card), cards.indexOf(nameCard));
  53.                     break;
  54.                 case "Shuffle":
  55.                     Collections.shuffle(cards);
  56.                     break;
  57.                 case "Reverse":
  58.                     Collections.reverse(cards);
  59.                     break;
  60.             }
  61.             line = scanner.nextLine();
  62.         }
  63.         System.out.println(String.join(" ",cards));
  64.     }
  65. }
  66. /*Problem 3. Wizard Poker
  67.  
  68. Create a program that adds, inserts, removes and swaps cards in a new deck.
  69. On the first line, you will receive all cards in the form of strings separated by ":".
  70. Until you receive the "Ready" command, you will get commands in the format:
  71.  
  72. Add {card name}
  73. Adds the card to the end of the deck.
  74. If the card doesn't exist in print "Card not found."
  75.  
  76. Insert {card name} {index}
  77. Insert the card at the given index of the deck.
  78. If the card doesn't exist or the index is invalid print "Error!"
  79.  
  80. Remove {card name}
  81. Remove the card from the deck.
  82. If the card doesn't exist in print "Card not found."
  83.  
  84. Swap {card name 1} {card name 2}
  85. Swap the positions of the cards.
  86.  
  87. Input will always be valid
  88.  
  89. Shuffle deck
  90.  
  91. Reverse the deck
  92.  
  93. When you receive the "Ready" command print the cards in the deck separated by space.
  94. Input
  95. On the 1st line, you will receive the arsenal of all cards available separated by ":".
  96. On the next lines, until you receive the "Ready" command you will receive commands to arrange your deck.
  97. Output
  98. Print the cards in your deck on a single line, separated by a single space.
  99. Examples
  100.  
  101. Input
  102. Innervate:Moonfire:Pounce:Claw:Wrath:Bite
  103. Add Moonfire
  104. Add Pounce
  105. Add Bite
  106. Add Wrath
  107. Insert Claw 0
  108. Swap Claw Moonfire
  109. Remove Bite
  110. Shuffle deck
  111. Ready
  112.  
  113. Output
  114. Wrath Pounce Claw Moonfire
  115.  
  116.  
  117. Comments
  118. First command is Add Moofire and now our deck has one card in it.
  119. 1. Moonfire Pounce
  120. 2. Moonfire Pounce Bite
  121. 3. Moonfire Pounce Bite Wrath
  122. 4. Claw Moonfire Pounce Bite Wrath
  123. 5. Moonfire Claw Pounce Bite Wrath
  124. 6. Moonfire Claw Pounce Wrath
  125. 7. Wrath Pounce Claw Moonfire
  126.  
  127.  
  128. Input
  129. Wrath:Pounce:Lifeweaver:Exodia:Aso:Pop
  130. Add Pop
  131. Add Exodia
  132. Add Aso
  133. Remove Wrath
  134. Add SineokBqlDrakon
  135. Shuffle deck
  136. Insert Pesho 0
  137. Ready
  138.  
  139. Output
  140. Card not found.
  141. Card not found.
  142. Error!
  143. Aso Exodia Pop
  144.                      */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement