diff --git a/src/Table.java b/src/Table.java new file mode 100644 index 0000000..5ce60e9 --- /dev/null +++ b/src/Table.java @@ -0,0 +1,113 @@ +public class Table { + private TableNode head; + private int length; + + public Table() { + head = null; + length = 0; + } + + public void add(Card card) { + TableNode newNode = new TableNode(card); + if (head == null) { + head = newNode; + } + else { + newNode.setNext(head); + head = newNode; + } + } + + public void removeSet(Card card1, Card card2, Card card3) { + if (card1.isSet(card2, card3) == false) { + return; + } + TableNode temp = head; + Card cardnum1 = null; + Card cardnum2 = null; + Card cardnum3 = null; + + while(temp !=null) { + if(temp.getCard() == card1) { + temp = temp.getNext(); + card1 = null; + } + } + } + + //while (curr != null) { + //if (curr.getCard() == card1) { + //cardnum1 = card1; + // } + //if (curr.getCard() == card2) { + //cardnum2 = card2; + //} + //if (curr.getCard() == card3) { + //cardnum3 = card3; + //} + //curr = curr.getNext(); + //} + + // while (curr == null) { + //if (curr.getCard() != card1) { + //cardnum1 = card1; + //} + //if (curr.getCard() != card2) { + //cardnum2 = card2; + //} + //if (curr.getCard() != card3) { + //cardnum3 = card3; + //} + //} + //} + + public int numCards() { + TableNode temp = head; + int card = 0; + if (temp == null) { + return 0; + } + else { + while (temp != null) { + card += 1; + temp = temp.getNext(); + } + return card; + } + } + + public Card getCard(int index){ + TableNode temp = head; + if(temp == null) { + return null; + } + for(int t = 0; t < index; t++) { + temp = temp.getNext(); + if(temp==null) { + return null; + } + } + return temp.getCard(); + } + + public int numSets() { + TableNode card1 = head; + TableNode card2 = head; + TableNode card3 = head; + int setnum = 0; + for (int a = 0; a < length - 2; a++) { + for (int b = 1; b < length - 1; b++) { + for (int c = 2; c < length; c++){ + + Card carda = getCard(a); + Card cardb = getCard(b); + Card cardc = getCard(c); + if(carda.isSet(cardb, cardc)) { + setnum += 1; + } + } + } + } + return setnum; + } +} diff --git a/src/TableNode.java b/src/TableNode.java new file mode 100644 index 0000000..67fefd5 --- /dev/null +++ b/src/TableNode.java @@ -0,0 +1,21 @@ +public class TableNode { + private Card card; + private TableNode next; + + public TableNode(Card card1) { + card = card1; + next = null; + } + + public void setNext(TableNode nextcard) { + next = nextcard; + } + + public TableNode getNext() { + return next; + } + + public Card getCard() { + return card; + } +} \ No newline at end of file diff --git a/src/TableNodeTest.java b/src/TableNodeTest.java new file mode 100644 index 0000000..0ce3e1a --- /dev/null +++ b/src/TableNodeTest.java @@ -0,0 +1,21 @@ +import junit.framework.TestCase; + +public class TableNodeTest extends TestCase { + + public void testTableNodeCards() { + Card card1 = new Card(1, 3, 3, 2); + TableNode node1 = new TableNode(card1); + assertEquals(null, node1.getNext()); + assertEquals(card1, node1.getCard()); + + Card card2 = new Card(1, 3, 1, 2); + TableNode node2 = new TableNode(card2); + assertEquals(null, node2.getNext()); + assertEquals(card2, node2.getCard()); + + Card card3 = new Card(1, 3, 2, 2); + TableNode node3 = new TableNode(card3); + assertEquals(null, node3.getNext()); + assertEquals(card3, node3.getCard()); + } +} \ No newline at end of file diff --git a/src/TableTest.java b/src/TableTest.java new file mode 100644 index 0000000..fd994f0 --- /dev/null +++ b/src/TableTest.java @@ -0,0 +1,21 @@ +import junit.framework.TestCase; + +public class TableTest extends TestCase{ + + public void testTable() { + Table tt = new Table(); + Card card1 = new Card(1, 2, 3, 2); + tt.add(card1); + + Card card2 = new Card(3, 2, 3, 1); + tt.add(card2); + + Card card3 = new Card(1, 2, 2, 3); + tt.add(card3); + + assertEquals(3, tt.numCards()); + assertTrue(tt.getCard(0).equals(card3)); + assertTrue(tt.getCard(1).equals(card2)); + assertTrue(tt.getCard(2).equals(card1)); + } +} \ No newline at end of file