Deck - int c1 c2 Random gen = new Random Card tempCard int...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.*; i class Deck { c static final int SIZE = 52; // static final for a constant Card[] cards; Deck(){ // make the deck array cards = new Card[SIZE]; // make cards to put into the deck for (int i=0; i<SIZE; i++) { cards[i] = new Card(); } } public void shuffle () { // pick two numbers at random between 0 and SIZE // then swap the two objects at those two array slots // do this a lot of time
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int c1, c2; Random gen = new Random(); Card tempCard; int nSwaps = 1000; for (int i=0; i<nSwaps; i++) { c1 = gen.nextInt(SIZE); c2 = gen.nextInt(SIZE); tempCard = cards[c1]; cards[c1] = cards[c2]; cards[c2] = tempCard; } } public void show (int len) { for (int i=0; i<SIZE; i++) { System.out.print(cards[i].getCNum()+" "); if ((i+1)%len == 0) System.out.println(); } } }...
View Full Document

This note was uploaded on 11/30/2009 for the course COMP 110 taught by Professor Stotts during the Spring '08 term at UNC.

Ask a homework question - tutors are online