// SetCard.java // NAME, ANDREW ID, SECTION public class SetCard { // Instance variables // YOU CHOOSE THESE! // Constructor: Create a SetCard instance with the given count, shape, // color, and fill, where each of these values is in the range [1,3]. public SetCard(int count, int shape, int color, int fill) { // YOU WRITE THIS } // Standard accessors // YOU WRITE THESE public int getCount() { return 42; } public int getShape() { return 42; } public int getColor() { return 42; } public int getFill() { return 42; } // Converts this SetCard to a unique index in the range [0,80], // assuming count, shape, color, and fill are all in the range [1,3]: // 27*(count - 1) + 9*(shape - 1) + 3*(color - 1) + (fill - 1) public int getCardIndex() { // YOU WRITE THIS return 42; } // Override equals method -- two set cards are equal if they // have the same count, shape, color, and fill public boolean equals(Object object) { // YOU WRITE THIS return false; } // Override hashCode method -- two equals SetCard instances must // have the same hashCode method. If you think about it, this // can be easily implemented by making use of the getCardIndex method... public int hashCode() { // YOU WRITE THIS return 42; } // Main public static void main(String[] args) { testSetCardClass(); } //////////////////////////////////// // testSetCardClass //////////////////////////////////// public static void testSetCardClass() { System.out.print("Testing SetCard class... "); SetCard setCard1 = new SetCard(1,2,3,2); assert(setCard1.getCount() == 1); assert(setCard1.getShape() == 2); assert(setCard1.getColor() == 3); assert(setCard1.getFill() == 2); int expectedCardIndex = ((1-1)*27 + (2-1)*9 + (3-1)*3 + (2-1)); assert(setCard1.getCardIndex() == expectedCardIndex); // This card equals the first card SetCard setCard2 = new SetCard(1,2,3,2); assert(setCard2.getCount() == 1); assert(setCard2.getShape() == 2); assert(setCard2.getColor() == 3); assert(setCard2.getFill() == 2); expectedCardIndex = ((1-1)*27 + (2-1)*9 + (3-1)*3 + (2-1)); assert(setCard2.getCardIndex() == expectedCardIndex); // And this one does not equal the previous two SetCard setCard3 = new SetCard(1,2,1,3); assert(setCard3.getCount() == 1); assert(setCard3.getShape() == 2); assert(setCard3.getColor() == 1); assert(setCard3.getFill() == 3); expectedCardIndex = ((1-1)*27 + (2-1)*9 + (1-1)*3 + (3-1)); assert(setCard3.getCardIndex() == expectedCardIndex); // Check equals method assert(setCard1.equals(setCard2) == true); assert(setCard1.equals(setCard3) == false); assert(setCard2.equals(setCard1) == true); assert(setCard2.equals(setCard3) == false); assert(setCard3.equals(setCard1) == false); assert(setCard3.equals(setCard2) == false); // Check hashCode method assert(setCard1.hashCode() == setCard2.hashCode()); assert(setCard1.hashCode() != setCard3.hashCode()); System.out.println("Passed all tests!"); } }