Pok - view source print ? 01 package javapoker; 02 03...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: view source print ? 01 package javapoker; 02 03 public class Card 04 { 05 private short rank, suit; 06 07 private static String suits = { "hearts", "spades", "diamonds", "clubs" }; 08 private static String ranks = { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" }; 09 10 public static String rankAsString( int __rank ) { 11 return ranks[__rank]; 12 } 13 14 Card(short suit, short rank) 15 { 16 this.rank=rank; 17 this.suit=suit; 18 } 19 20 public @Override String toString() 21 { 22 return ranks[rank] + " of " + suits[suit]; 23 } 24 25 public short getRank() { 26 return rank; 27 } 28 29 public short getSuit() { 30 return suit; 31 } 32 } So we have read-only suit and rank variables, a simple constructor, a toString method, and a rankAsString method. The class will be ultra fast as it knows which strings to output just by accessing indexes of static arrays. This array functions as a dictionary, allowing us to convert an accessing indexes of static arrays....
View Full Document

This note was uploaded on 10/11/2010 for the course CS 230 taught by Professor Tanner during the Fall '10 term at West Virginia State University.

Page1 / 4

Pok - view source print ? 01 package javapoker; 02 03...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online