Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package _08_setsAndMaps_Exercises;
- import java.util.*;
- public class _08_HandsOfcards {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Map<String, Set<String>> cardsByPlayer = new LinkedHashMap<>();
- String input = "";
- while (!"JOKER".equals(input = sc.nextLine())) {
- String[] data = input.split(": ");
- cardsByPlayer.putIfAbsent(data[0], new HashSet<>());
- Set<String> hand = cardsByPlayer.get(data[0]);
- String[] cardLine = data[1].split(", ");
- hand.addAll(Arrays.asList(cardLine));
- }
- for (Map.Entry<String, Set<String>> entry : cardsByPlayer.entrySet()) {
- System.out.print(entry.getKey() + ": ");
- int sum = 0;
- int val = 0;
- for (String card : entry.getValue()) {
- String power = card.substring(0, card.length() - 1);
- String type = card.substring(card.length() - 1);
- int typeValue = 0;
- int powerValue = 0;
- switch (type) {
- case "S":
- typeValue = 4;
- break;
- case "H":
- typeValue = 3;
- break;
- case "D":
- typeValue = 2;
- break;
- case "C":
- typeValue = 1;
- break;
- }
- switch (power) {
- case "J":
- powerValue = 11;
- break;
- case "Q":
- powerValue = 12;
- break;
- case "K":
- powerValue = 13;
- break;
- case "A":
- powerValue = 14;
- break;
- default:
- powerValue = Integer.parseInt(power);
- }
- val = powerValue * typeValue;
- sum += val;
- }
- System.out.print(sum);
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement