Skip to content

Commit

Permalink
New Table
Browse files Browse the repository at this point in the history
  • Loading branch information
mpacitti committed Apr 16, 2015
1 parent 7d5d730 commit 830ecb2
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 66 deletions.
124 changes: 61 additions & 63 deletions src/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,62 +18,62 @@ public void add(Card card) {
}
}

public void removeSet(Card card1, Card card2, Card card3) {
if (card1.isSet(card2, card3) == false) {
return;
public boolean onTable(Card card){
TableNode node = head;
while (node != null) {
if (node.getCard().equals(card)) {
return true;
}
node = node.getNext();
}
TableNode temp = head;
Card cardnum1 = null;
Card cardnum2 = null;
Card cardnum3 = null;

while(temp !=null) {
if(temp.getCard() == card1) {
temp = temp.getNext();
card1 = null;
return false;
}


public void removeCard(Card card){
TableNode newnode = null;
TableNode node = head;
while (node != null) {
if (node.getCard().equals(card)) {
if (newnode == null) {
head = node.getNext();
}
else {
newnode.setNext(node.getNext());
}
return;
}
newnode = node;
node = node.getNext();
}
}

public void removeSet(Card card1, Card card2, Card card3) {
TableNode node = head;
TableNode curr = 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;
//}
//}
//}
if(!card1.isSet(card2, card3)){
return;
}
if(!onTable(card1) || !onTable(card2) || !onTable(card3)){
return;
}
removeCard(card1);
removeCard(card2);
removeCard(card3);
}

public int numCards() {
TableNode temp = head;
int card = 0;
int numcount = 0;
if (temp == null) {
return 0;
}
else {
while (temp != null) {
card += 1;
temp = temp.getNext();
}
return card;
while (temp != null) {
numcount += 1;
temp = temp.getNext();
}
return numcount;
}

public Card getCard(int index){
Expand All @@ -90,24 +90,22 @@ public Card getCard(int index){
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;

public int numSets(){
int length = numCards();
int count = 0;
for(int i= 0; i < length; i++){
Card icard = getCard(i);
for(int j = i + 1; j < length; j++){
Card jcard = getCard(j);
for(int k = j + 1; k < length; k++){
Card kcard = getCard(k);
if(icard.isSet(jcard, kcard)){
count++;
}
}
}
}
return count;
}
}
13 changes: 10 additions & 3 deletions src/TableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

public class TableTest extends TestCase{

public void testTable() {
public void testEmpty() {
Table tt = new Table();
Card card1 = new Card(1, 2, 3, 2);
assertEquals(0, tt.numCards());
assertEquals(null, tt.getCard(0));
assertEquals(0, tt.numSets());
}

public void testCards() {
Table tt = new Table();
Card card1 = new Card(2, 1, 3, 2);
tt.add(card1);

Card card2 = new Card(3, 2, 3, 1);
Expand All @@ -16,6 +23,6 @@ public void testTable() {
assertEquals(3, tt.numCards());
assertTrue(tt.getCard(0).equals(card3));
assertTrue(tt.getCard(1).equals(card2));
assertTrue(tt.getCard(2).equals(card1));
assertTrue(tt.getCard(2).equals(card1));
}
}

0 comments on commit 830ecb2

Please sign in to comment.