Deck class_Almafrachi.docx - package cardgame Marwan Al-mafrachi Exercise-3 Deck Class import java.util.Random public class Deck private Card deck

# Deck class_Almafrachi.docx - package cardgame Marwan...

• Lab Report
• 4

This preview shows page 1 - 3 out of 4 pages.

package cardgame;/** MarwanAl-mafrachi* Exercise-3* Deck Class* 04/24/2017*/import java.util.Random;public class Deck {private Card [] deck;private int position;private int counter;private String name;private Card[] hand;private int numCards;Deck(){position = -1;deck = new Card[52];hand = new Card[10];int i = 0;for ( i = 0; i < 13; i++){deck [i] = new Card(i+1,'h');//System.out.println(deck[i]);}for(i = 13;i < 26; i++){deck [i] = new Card(i-12,'s');//System.out.println(deck[i]);}for ( i = 26; i < 39; i++){deck [i] = new Card(i-25,'c');//System.out.println(deck[i]);}for ( i = 39; i <52; i++){deck [i] = new Card(i-38,'d');//System.out.println(deck[i]);}}// end for/******************************************************/public void shuffle(){int i;int k=0;int m =0;position =0; for (i = 0; i < 100; i++){Random generator = new Random();k= generator.nextInt(52);m = generator.nextInt(52);//System.out.println(k + " "+ m);Card temp =deck[k];deck[k]= deck[m];deck[m]=temp;i++;}// end shuffle}// end for/******************************************************/public Deck (String aName){name = aName;emptyHand();}// end namepublic void emptyHand(){
for (int c = 0; c< 10; c++){hand[c] = null;}numCards = 0;}// end emptyHandpublic boolean addCard(Card aCard){if(numCards == 10){System.err.println(" player gets more than 10 cards " + name);