import java.util.Scanner; public class Pile extends QueueArray { public Pile(String cards) { // Allows for the construction of a pile of cards from a string // // Example: // Pile pile = new Pile("As 2s 3s Jh Qh Kh 4d 5d 6d 7c 8c 9c"); Scanner scanner = new Scanner(cards); while (scanner.hasNext()) { String card = scanner.next(); this.enqueue(new Card(card.charAt(0),card.charAt(1))); } scanner.close(); } public String toString() { // Creates a string containing 10 cards per line, for as many lines // as necessary to show all cards in the pile // // Example: // 6h 3h Jc Ts 3c 7h 2h 9c 3s 7s // 8c 5d Js Jh 6d Ah Qh 9d Ks 6c // Kc Td Jc Th 9s Kd String s = ""; int i = 0; for (Card card : this) { s += card + " "; if (i % 10 == 9) s += System.lineSeparator(); i = (i+1) % 10; } return s; } }