Introduction to OOP | Chapter 4: Classes and Methods: | next | previous | audio | real | text |
class PlayingCard { // constructor, initialize new playing card public PlayingCard (Suits is, int ir) { suit = is; rank = ir; faceUp = true; } // operations on a playing card public boolean isFaceUp () { return faceUp; } public int rank () { return rankValue; } public Suits suit () { return suitValue; } public void setFaceUp (boolean up) { faceUp = up; } public void flip () { setFaceUp( !faceUp);} public Color color () { if ((suit() == Suits.Diamond) || (suit() == Suits.Heart)) return Color.Red; return Color.Black; } // private data values private Suits suitValue; private int rankValue; private boolean faceUp; }