// return a String representation of a list of Cards public static String cardsToString(List<Card> cards, String delimiter) { StringBuilder sb = new StringBuilder(); String prefix = ""; for (Card card : cards) { sb.append(prefix); sb.append(card.toString()); prefix = delimiter; } return sb.toString(); }
public String toString() { String a = ""; for (Card b : cards) a += b.toString() + "\n"; return a; }
/** * Main class that test the functionality of methods in Card and BinSet class. * * @param args */ public static void main(java.lang.String[] args) { Card one = new Card(Ranks.FIVE, "SPADES"); Card two = new Card(Ranks.NINE, "HEARTS"); Card three = new Card(Ranks.KING, "DIAMONDS"); Card four = new Card(Ranks.ACE, "DIAMONDS"); Card five = new Card(Ranks.ACE, "CLUBS"); Card six = new Card(Ranks.FIVE, "SPADES"); System.out.println("Five of Spades equals Nine of Hearts:"); System.out.println(one.equals(two)); System.out.println(); System.out.println("Five of Spades equals King of Diamonds:"); System.out.println(one.equals(three)); System.out.println(); System.out.println("Five of Spades equals Ace of Diamonds:"); System.out.println(one.equals(four)); System.out.println(); System.out.println("Five of Spades equals Ace of Clubs:"); System.out.println(one.equals(five)); System.out.println(); System.out.println("Five of Spades equals Five of Spades:"); System.out.println(one.equals(six)); System.out.println(); System.out.println("___________________________________________________"); System.out.println("Value is greater than 0 when 1 is compared to 2."); System.out.println(one.compareTo(two)); System.out.println(); System.out.println("Value is greater than 0 when 1 is compared to 3."); System.out.println(one.compareTo(three)); System.out.println(); System.out.println("Value is greater than 0 when 1 is compared to 4."); System.out.println(one.compareTo(four)); System.out.println(); System.out.println("Value is greater than 0 when 1 is compared to 5."); System.out.println(one.compareTo(five)); System.out.println(); System.out.println("Value is equal to 0 when 1 is compared to 6."); System.out.println(one.compareTo(six)); System.out.println(); System.out.println("___________________________________________________"); System.out.println("Card1 as a String:"); System.out.println(one.toString()); System.out.println(); System.out.println("Card2 as a String:"); System.out.println(two.toString()); System.out.println(); System.out.println("Card3 as a String:"); System.out.println(three.toString()); System.out.println(); System.out.println("Card4 as a String:"); System.out.println(four.toString()); System.out.println(); System.out.println("Card5 as a String:"); System.out.println(five.toString()); System.out.println(); System.out.println("Card6 as a String:"); System.out.println(six.toString()); System.out.println(); System.out.println("___________________________________________________"); System.out.println("Create List1."); BinSet<String> List1 = new BinSet<String>(); System.out.println(); System.out.println("Add A to List1:"); System.out.println(List1.add("A")); System.out.println(); System.out.println("Add B to List1:"); System.out.println(List1.add("B")); System.out.println(); System.out.println("Add A to List1:"); System.out.println(List1.add("A")); System.out.println(); System.out.println("Print out List1:"); System.out.println(List1.toString()); System.out.println(); System.out.println("___________________________________________________"); System.out.println("Create List2."); Collection<String> List2 = new ArrayList<String>(); System.out.println(); System.out.println("Add C to List2:"); List2.add("C"); System.out.println("Add D to List2:"); List2.add("D"); System.out.println("Add E to List2:"); List2.add("E"); System.out.println(); System.out.println("Are we able to add List2 to List1?"); System.out.println(List1.addAll(List2)); System.out.println(); System.out.println("Clear List2."); List2.clear(); System.out.println(); System.out.println("Add A to List2."); List2.add("A"); System.out.println("Add C to List2."); List2.add("C"); System.out.println("Add D to List2."); List2.add("D"); System.out.println("Add E to List2."); List2.add("E"); System.out.println(); System.out.println("Can I add List2 to List1?"); System.out.println(List1.addAll(List2)); System.out.println(); System.out.println("Display List1:"); System.out.println(List1.toString()); System.out.println(); System.out.println("Is List2 Empty?"); System.out.println(List2.isEmpty()); System.out.println(); System.out.println("Clear List2."); List2.clear(); System.out.println(); System.out.println("Is List2 Empty?"); System.out.println(List2.isEmpty()); System.out.println(); System.out.println("Can I add List1 to List2?"); System.out.println(List2.addAll(List1)); System.out.println(); System.out.println("Does List1 Contain all of List2?"); System.out.println(List1.containsAll(List2)); System.out.println(); System.out.println("Does List2 Contain Z?"); System.out.println(List2.contains("Z")); System.out.println(); System.out.println("Does List2 Contain A?"); System.out.println(List2.contains("A")); System.out.println(); System.out.println("Can I remove Z from List2?"); System.out.println(List2.remove("Z")); System.out.println(); System.out.println("Can I remove A from List2?"); System.out.println(List2.remove("A")); System.out.println(); System.out.println("Display List2:"); System.out.println(List2.toString()); System.out.println(); System.out.println("Display List1:"); System.out.println(List1.toString()); System.out.println(); Object[] array = List1.toArray(); System.out.println("Display the array created from List1:"); System.out.println(Arrays.toString(array)); System.out.println(); }