package hw17; public class DeckOfCard { private PlayingCard [] deck = new PlayingCard[52]; private int cardDealt = 0; private String [] s = new String[52]; private int cardRemained = 52; public DeckOfCard() { for(int i =0; i<13; i++) { for(int j =0;j<4;j++) { deck[i*4+j] = new PlayingCard(i+1,j+1); } } } public PlayingCard dealNextCard() { PlayingCard b = deck[cardDealt]; cardDealt += 1; return b; } public int cardsRemaining() { cardRemained -= cardDealt; return cardRemained; } private void swap(int a, int b) { PlayingCard temp; temp = deck[a]; deck[a] = deck[b]; deck[b] = temp; } public void shuffle() { cardDealt = 0; for(int i=1; i<52; i++) { int index = (int)(Math.random()*52); swap(index,i); } for(int i=0; i<52; i++) { int randomNum = (int)(Math.random()*52); int temp; temp = i; s[i] = s[randomNum]; s[randomNum] = s[temp]; } } public String toString() { String arrayS = " "; for(int i=0; i<52;i++) { s[i] = deck[i].toString(); arrayS += s[i]+"\n"; } return arrayS; } }