0

Working solution:

public void checkMatch(){
		boolean stop = true;
		for(CardHolder h: holders){
			System.out.println("Checking stack");
			
			if(topCards.size() > 2){ //means can never be a match
				stop = true;
			}
			else if(topCards.containsKey(h.topCard())){ //else no match add card(if contained update)
				Integer i = (Integer) topCards.get(h.topCard());
				int it = i.intValue();
				it++;
				Integer p = new Integer(it);
				topCards.put(h.topCard(),p);
				System.out.println("update existing card");
				System.out.println(""+topCards.get(h.topCard()));
				stop = false;
			}
			
			else{									//first time card added, add and put value as 1
				topCards.put(h.topCard(), 1);
				System.out.println("adding new card");
				stop = false;
			}
		}
		
		if(!stop){
			for(CardHolder h: holders){
				System.out.println("hello");
				Cards c = h.topCard();
				Integer i = (Integer) topCards.get(c);
				int in = i.intValue();
				if (in == (n-1)){
					player.add(h.takeTopCard()); 
					System.out.println("Matcha!");   	  
				}
			}
		}
		System.out.println("clearing hashtable");
		topCards.clear();
}
0

Glad to hear that it's working :)

At a glance I just found one thing that you can change to a nicer format:

int it = i.intValue();
it++;
Integer p = new Integer(it);
topCards.put(h.topCard(),p);

To

Integer p = new Integer(++i.intValue());
topCards.put(h.topCard(),p);

But it is not necessary. Glad we could help you :) please mark the thread as solved.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.