import java.lang.; import java.text.; import java.util.; - import java.lang import java.text import java.util public class DeckofCards private

Import java.lang.; import java.text.; import java.util.;

This preview shows page 1 - 6 out of 15 pages.

import java.lang.*; import java.text.*; import java.util.*; public class DeckofCards { private static Card[] cards;//the array of cards private static int numCards;//the number of cards in the deck public DeckofCards(boolean shuffle) { numCards = 52; cards = new Card[numCards]; int cardIndex = 0; //for each suit of cards for(int suit = 0; suit < 4; suit++) { for(int faceVal = 1; faceVal <= 13; faceVal ++) { //add a new card to deck cards[cardIndex] = new Card(suit, faceVal); cardIndex++; } }
//if the user wants to shuff if(shuffle == true) { DeckofCards.shuffle(); } }//end constructor public static void shuffle() { //initialize random number generator Random shuffleDeck = new Random(); //temporary card value Card temp; int tempIndex; for(int i = 0; i < numCards; i++) { //get a random card to swap tempIndex = shuffleDeck.nextInt(numCards); //swap the cards temp = cards[i]; cards[i] = cards[tempIndex]; cards[tempIndex] = temp; }
}//end shuffle public Card dealNextCard() { //get the top card Card top = cards[0]; for(int c = 1; c < numCards; c++) { cards[c - 1] = cards[c]; } cards[numCards - 1] = null; numCards--; return top; }//end dealNextCard public void printDeck() { for(int c = 0; c < numCards; c++) { System.out.println(cards[c]); } }//end printDeck } //ListNOde public class ListNodes { //Instance data ��
//Nodes I use to traverse the list �� Node head; //points to first node Node first; //temp position for first node Node current; //node currently being processed Node prev; //node previously processed //Fields of the node String firstName; //Student's first name String lastName; //Student's last name �� Node next; //next node in list �� public ListNodes() �� { �� head = null; //empty list } ��

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture