Comment

Card
Card,
March 23, 2010 at 1:41 PM

// Card.java - John K. Estell - 8 May 2003
// last modified: 23 Febraury 2004
// Implementation of a playing card. Uses classes Rank and Suit for
// expressing the card value.

import javax.swing.*;


/**
* Representation of a single playing card. A card consists of a suit value
* (e.g. hearts, spades), a rank value (e.g. ace, 7, king), and an image of
* the front of the card. A card object is immutable; once instantiated, the
* values cannot change.
*
* @author John K. Estell
* @version 1.0
*/
public class Card implements Comparable {

// instance variables for the card
private Suit suitValue;
private Rank rankValue;
private ImageIcon cardImage;
private static boolean sortRankMajorOrder = true;


/**
* Creates a new playing card.
* @param suit the suit value of this card.
* @param rank the rank value of this card.
* @param cardFace the face image of this card.
*/
public Card( Suit suit, Rank rank, ImageIcon cardFace ) {
cardImage = cardFace;
suitValue = suit;
rankValue = rank;
}


/**
* Generates the filename associated with the card. <code>getFilename</code> assumes that all of the standard card images
* are stored in individual files using filenames in the form of:
* <b>RS.gif</b> where <b>R</b> is a single character used to represent
* the rank value of the card and <b>S</b> is a single character used to represent
* the suit value of the card.
* <p>The characters used for <b>R</b> are:
* 'a' (ace), '2', '3', '4', '5', '6', '7', '8', '9',
* 't' (10), 'j' (jack), 'q' (queen), and 'k' (king).
* <p>The characters used for <b>S</b> are:
* 'c' (clubs), 'd' (diamonds), 'h' (hearts), and 's' (spades).
* <p>Two other cards are also available: "b.gif" (back of card) and "j.gif" (joker).
*
* @param suit the suit value of the card.
* @param rank the rank value of the card.
* @return a string containing the filename of the card.
*/
public static String getFilename( Suit suit, Rank rank ) {
return rank.getSymbol() + suit.getSymbol() + ".gif";
}


/**
* Returns the suit of the card.
* @return a Suit constant representing the suit value of the card.
*/
public Suit getSuit() {
return suitValue;
}


/**
* Returns the rank of the card.
* @return a Rank constant representing the rank value of the card.
*/
public Rank getRank() {
return rankValue;
}


/**
* Returns the graphic image of the card.
* @return an icon containing the graphic image of the card.
*/
public ImageIcon getCardImage() {
return cardImage;
}


/**
* Returns a description of this card.
* @return the name of the card.
*/
public String toString() {
return rankValue.toString() + " of " + suitValue.toString();
}


/**
* Returns a description of the rank of this card.
* @return the rank value of the card as a string.
*/
public String rankToString() {
return rankValue.toString();
}


/**
* Returns a description of the suit of this card.
* @return the suit value of the card as a string.
*/
public String suitToString() {
return suitValue.toString();
}


/**
* Specifies that cards are to be sorted in rank-major order. Cards are ordered
* first by their rank value; cards of the same rank are then ordered by their
* suit value.
*/
public static void setRankMajorSort() {
sortRankMajorOrder = true;
}


/**
* Specifies that cards are to be sorted in suit-major order. Cards are ordered
* first by their suit value; cards of the same suit are then ordered by their
* rank value.
*/
public static void setSuitMajorSort() {
sortRankMajorOrder = false;
}


/**
* Compares two cards for the purposes of sorting.
* Cards are ordered first by their suit value, then by their
* rank value.
* @param otherCardObject the other card
* @return a negative integer, zero, or a positive integer is this card is
* less than, equal to, or greater than the referenced card.
*/
public int compareTo( Object otherCardObject ) {
Card otherCard = (Card) otherCardObject;
int suitDiff = suitValue.compareTo( otherCard.suitValue );
int rankDiff = rankValue.compareTo( otherCard.rankValue );

if ( sortRankMajorOrder ) {
if ( rankDiff != 0 )
return rankDiff;
else
return suitDiff;
}
else {
if ( suitDiff != 0 )
return suitDiff;
else
return rankDiff;
}
}


/**
* Compares two cards to determine if they have the same value.
* This is not the same as the use of <code>equals</code> which compares
* two objects for equality.
* @param card the other card
* @return <code>true</code> if the two cards have the same rank and suit
* values, <code>false</code> if they do not.
*/
public boolean isSameAs( Card card ) {
if ( ( rankValue != card.rankValue ) || ( suitValue != card.suitValue ) )
return false;
else
return true;
}
public static void main(String[] args)
{
card[] deck = new card[52];
String r[] = {"ACE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN","JACK","QUEEN","KING"};
String s[] = {"CLUBS","DIAMONDS","HEARTS","SPADES"};
for (int h = 0; h < s.length; h++)
{

for (int j = 0; j < r.length; j++)
{
deck = new card(s,[j+1]);
}
}
}

}

View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Tools For Java Technology

Java Debugger,Java Debuggers
Java Debugger       Java debugger helps in finding and the fixing of bugs in Java language programs. The Java debugger is denoted as jdb. It works like a command-line 

Java-Tutorials

Java Debugger
Java Debugger       Java debugger helps in finding and the fixing of bugs in Java language programs. The Java debugger is denoted as jdb. It works like a command-line 

General

Java Debugger
Java Debugger       Java debugger helps in finding and the fixing of bugs in Java language programs. The Java debugger is denoted as jdb. It works like a command-line 

Java Tools

Java Debugger
Java Debugger       Java debugger helps in finding and the fixing of bugs in Java language programs. The Java debugger is denoted as jdb. It works like a command-line debugger 

Mobile Applications Questions

What is Java Card ?
What is Java Card ?  hii, What is Java Card ?   hello, The Java Card specification allows Java technology to run on smart cards and other small devices 

Java Beginners

Problem in card demo example.
Problem in card demo example.  Hi, I have successfully shows... one card of bunch, then its shows back of its above card, hence the top most card is the one card that shows full when drag and move around the screen. please 

Programming Tutorials

Master java in a week
;    Class Declaration: Class is the building block in Java...; The main method is the entry point in the Java program and java program can't run... is always first thing that is executed in a java program. Here is the main method 

Java Beginners

credit card problem - Java Beginners
credit card problem  Say that you owe the credit card company $1000.00. The company charges you 1.5% per month on the unpaid balance. You have decided to stop using the card and to pay off the debt by making a monthly payment 

Java Beginners

Credit Card Validation - Java Beginners
Credit Card Validation  i have to do a project for my comp sci class. yet i dont know how to select the last digit of a credit card number strings... up the digits in the credit card number, working from right to left 

Java Beginners

Problem in show card in applet.
Problem in show card in applet.  The following link contained the card demo with applet. http://www.roseindia.net/java/java... On Run as Java Applet then only show the Applet, not show any one card,hence any 

Programming Tutorials

Java Swing Card Layout
Java Swing Card Layout Java technology uses Layout Managers to define... layout manager. Multiple components on card can be added but at a time only one card can be seen. Here is the code: import java.awt.*; import 

General

Master Java In A Week
Master Java In A Week Master Java Programming Language in a week... by the Operating System.   Debugger Java debugger helps in finding and the fixing of bugs in Java language programs 

General

Change Background of Master Slide Using Java
Change Background of Master Slide Using Java  ... to create a slide then change background of the master slide. In this example we are creating a slide master for the slide show. To create slide show we 

WebSevices Questions

Internet and Web related questions for Web Master.
Internet and Web related questions for Web Master.   Explain the difference between the Internet and Web. What are Web browsers? Explain the two main... is Java? What are the applications of Java that you can use for Web designing 

Security Questions

How to send request to the visa/master card to get verifed the credit card - Security
How to send request to the visa/master card to get verifed the credit card  Sending request to verify the card number 

Security Questions

How to send request to the visa/master card to get verifed the credit card - Security
How to send request to the visa/master card to get verifed the credit card  we are accepting the credit card number, So how to forward request get verified the card number. Thanks You 

Security Questions

How to send request to the visa/master card to get verifed the credit card - Security
How to verifed the credit card  Can anyone please explain me ...how to verify the card number while accepting payment online 

Java Beginners

debugger
 

Java Beginners

java
java  hi im new to java plz suggest me how to master java....saifjunaid@gmail.com 

Java Interview Questions

java
java  what are abstract methods   Please visit the following link: http://www.roseindia.net/java/master-java/abstract-class.shtml 

Java Beginners

java
, visit the following links: http://www.roseindia.net/java/master-java/java-left-shift.shtml http://www.roseindia.net/java/master-java/java-right-shift.shtml 

Java Beginners

java
://www.roseindia.net/help/java/a/java-abstract-class.shtml http://www.roseindia.net/java/master-java/abstract-class.shtml 

General

Learn the Java 8 and master the new features of JDK 8
JDK 8 - Java 8 Tutorial and examples: Learn JDK 8 with the help of examples...; Lambdas, Functional interface, Accumulators, Stream, Time API etc. and other Java bug fixes. Here we are giving the news, articles and updates of Java

Java Beginners

java
??all the database must be in master computer only and all other computer must retrieve that data from the master computer only.please help 

Java Beginners

java - Java Beginners
java  Where are the card layouts used 

Eclipse Plugins

Masters of Java Assignment Plugin
it significantly easier to develop Master of Java Assignments by making use of the Eclipse Java IDE.  The plugin has the following features... Masters of Java Assignment Plugin   

Java Beginners

a java program111 - Java Beginners
a java program111  write a detailed program on the following topic: Student"s report card 

Java Beginners

Java - Java Beginners
Java  Java Master get ready.... Can we make plugin for Browser in java ? Any reply is appriciated 

Java Tips and Examples

Java as a general purpose language
Java as a general purpose language       Java is an Object oriented application programming language developed by Sun Microsystems. Java is a very powerful general-purpose 

Java Beginners

java code - Java Beginners
, Please visit the following links: http://www.roseindia.net/java/master-java/abstract-class.shtml http://www.roseindia.net/java/master-java/interface.shtml...java code  when will go for abstract and when will go for interface 

Java-Tutorials

Java Courses
RoseIndia Java Courses provided online for free can be utilized by beginners in Java anywhere in the world. They can use this course to master Java language and become Java developers. The courses provided here cover every topic 

JSP Servlet Questions

java - JSP-Servlet
master/visa credit cards. But without swiping the card how the transaction takes... your card. Regards Rajanikant 

General

Java AWT Package Example
Java AWT Package Example       In this section you will learn about the AWT package of the Java. Many running examples are provided that will help you master AWT package. Example 

Blog

Sitemap Java Tutorial Section
in JAVA | Master Java Tutorials (TOC) | Java  programming language... browsers | Java Compiler | Java Interpreter  | Java Debugger | Java... | Site Map | Business Software Services India Java Tutorial Section 

Java Beginners

Printer in java
Printer in java  hi how to print jframe contents in java swings like we want to print a report card how to print report card same as we are looking 

Java Beginners

core java - Java Beginners
/java/language/java-keywords.shtml http://www.roseindia.net/java/master-java/java-keywords.shtml Thanks...core java  how many keywords are in java? give with category?  

Java Beginners

java - Java Beginners
://www.roseindia.net/java/master-java/java-a-general-purpose-languaage.shtml http://www.roseindia.net/java/master-java/index.shtml http://www.roseindia.net/java/master...java  hi, i'm chandrakanth.k. i dont know about java. but i'm 

Java Interview Questions

java - Java Interview Questions
java  what is the use of marker interface?????  Hi Friend, Please visit the following link: http://www.roseindia.net/java/master-java/interface.shtml Thanks 

Java Beginners

java - Java Beginners
java  where do i declare an enum?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/master-java/enum.shtml Thanks 

Java Beginners

java - Java Beginners
java  hi sir/mam i'm Gomathi...... what is called interface? it has any definition?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/master-java/interface.shtml Thanks 

Java-Tutorials

Java made easy
but to master it. The duration of the Java course is not fixed...RoseIndia has made learning Java easy with its online Java course, Java tutorials, java projects, Java programs, Java video tutorials and Java lectures 

Java Beginners

stacks in java - Java Beginners
the role of spider card game. i have to move more than one card together from one column to another i can move one card usinf pop and push method but if its more that one card togther for example if i want to move 6,5 and 4 to put 

Java Beginners

java - Java Beginners
java  Where are the card layouts used?   Hi Friend, Card Layouts are used in Java Swing. Here is one example. import java.awt.... CardLayoutExample() { setTitle("Card Layout Example"); setSize 

Java Beginners

core java - Java Beginners
"); } } ------------------------------------------- Read for more information. http://www.roseindia.net/java/master-java/index.shtml Thanks...core java  how to write a simple java program?  Hi friend 

Java Beginners

java - Java Beginners
://www.roseindia.net/java/master-java/method_overloading.shtml http.../java/master-java/abstract-class.shtml http://www.roseindia.net/java/javascript...java   your website is best look i am intension of this java 

Java Beginners

java - Java Beginners
the following links: http://www.roseindia.net/help/java/p/polymorphism.shtml http://www.roseindia.net/java/master-java/method_overloading.shtml http... may refer to different methods. In java,there are two type of polymorphism 

Java-Tutorials

Java for complete beginners
Java Guide is available at RoseIndia that help beginners to master... and application development for mobile phone, Java is in great demand and so are Java developers. Java platform is flexible, a program developed in it can run 

Java Beginners

New To JAVA - Java Beginners
://www.roseindia.net/java/master-java/index.shtml Thanks...New To JAVA  hi iam new to java..,can you please guide me how to learn the java and also tell me how many days it takes to learn java  Hi 

Java Beginners

Java Abstraction - Java Beginners
Friend, Please visit the following links: http://www.roseindia.net/java/master-java/abstract-class.shtml http://www.roseindia.net/help/java/a/java-abstract...Java Abstraction  If we declare a class as abstract then it contains 

Training

Java Web Services Online Training
of Java Web services. syllabus and what it takes to master java web services...Java Web Services Online Training Java Web Services online training enables students and learners to make interactive web based services using Java and its 

Java Interview Questions

java - Java Interview Questions
read the given tutorial. http://www.roseindia.net/java/master-java/abstract...Java Abstract Class and Interface Info  What are the Java Abstract Class and Interfaces?  Hi Bharathi Abstract Class - a class which 

Java Beginners

Core java - Java Beginners
://www.roseindia.net/java/master-java/inheritance.shtml Thanks  Hi... multiple inheritance from java is removed.. with any example.. Thank you... of Interfaces in Java Thanks 

Java Beginners

java programming problem - Java Beginners
java programming problem   Given a deck of ncards unique cards.Cut the deck iCut cards from the top portion of the deck followed by the bottom card... etc. Alternating the remaining cards go on top. The problem is to find 

Java Interview Questions

java - Java Interview Questions
or the Java Development Kit is a set of a Java compiler, a Java interpreter, developer tools, Java API libraries, documentation which can be used by Java developers to develop Java-based applications.JDK is Java development kit. It is used 

Java Beginners

Java Project - Java Beginners
these modules. All these modules are using more than two common master files i.e. employee master. Now, can you tell in Java programming with Mysql How can...Java Project  Dear Sir, I have to do Project in "IT in HR i.e. 

JSP Servlet Questions

java code - JSP-Servlet
java code  how to read SMS from a connected SIM Card to a web application 

General

Java Tools
Java Debugger Java debugger helps in finding and the fixing of bugs... Java Tools       Java Compiler To commence with Java programming, we must know 

General

Java Tools
Java Debugger Java debugger helps in finding and the fixing of bugs... Java Tools       Java Compiler To commence with Java programming, we must know 

Java Beginners

javascript - Java Beginners
; select Master Card Visa American express Card Number* ...javascript  hallo sir i am beginer in java please provide me...("Please enter card Number!"); theForm.cnumber.focus(); return false 

Java Beginners

java - Java Beginners
: http://www.roseindia.net/help/java/m/method-overloading-in-java.shtml http://www.roseindia.net/java/master-java/method_overloading.shtml http://www.roseindia.net/java/javascript-array/modified-java-method-overriding.shtml http 

Java Beginners

java
java  diff bt core java and java 

Java Beginners

java object - Java Beginners
information. http://www.roseindia.net/java/master-java/variables-in-java.shtml...java object  i want to where in the memory the java objects,local variables,instances variables,static variables,final variables,methods 

Java Beginners

java - Java Beginners
information : http://www.roseindia.net/java/master-java/inheritance.shtml Thanks...java  Why java does not support multiple inhertance?  Hi... the interface. In Java Multiple Inheritance can be achieved through use of Interfaces 

Java Beginners

Java for beginners
for beginners Learn Java in a day Master Java in a week All Java tutorials...Java for beginners  Java for beginners Which is the best resource to learn Java programming lanuage? Which is the best resource for learning Java 

Java Interview Questions

java
java  what is java 

Java-Tutorials

Learn Java online
and eventually master it. The other fact is learning Java online is free...Learning Java is now as easy as never before. Many websites today provide the facility of learning Java programming online by providing enough material like 

Java Beginners

java - Java Beginners
links: http://www.roseindia.net/java/java-tips/language/10basics/import.shtml http://www.roseindia.net/java/master-java/enum.shtml http://www.roseindia.net/java/java-tips/oop/constructors/constructor.shtml Thanks 

Java Beginners

java - Java Beginners
/java/master-java/java-object-oriented-language.shtml Thanks 

Java Beginners

core java - Java Beginners
://www.roseindia.net/java/master-java/interface.shtml Thanks...core java  When we will use marker interface in our application?  Hi friend, Marker Interface : In java language programming 

Programming Tutorials

An Overview of Java      Java is a programming language      Java is Object Oriented Programming
Master java in a week      ....   Debugger Java debugger helps in finding and the fixing of bugs in Java language programs. The Java debugger is denoted as jdb 

Java Interview Questions

Java - Java Interview Questions
Java  Respected Sir/Madam First i can introduce my self, Am Ashok Kumar C from Tamilnadu, I am going to finish Master Degree In Computer... Interview interview, Tech are c++, java,  Hi friend, Now get more 

Java Beginners

java - Java Beginners
to : http://www.roseindia.net/java/master-java/interface.shtml http://www.roseindia.net/java/master-java/abstract-class.shtml http://www.roseindia.net/interviewquestions/corejava.shtml http://www.roseindia.net/java/master-java 

Java Beginners

java - Java Beginners
the following links: http://www.roseindia.net/java/master-java/interface.shtml http://www.roseindia.net/java/master-java/abstract-class.shtml Thanks 

Java Beginners

java from Scratch - Java Beginners
/java/master-java/index.shtml Thanks...java from Scratch  Hi experts, I am new one in dotnet ,I want to switch to java side,& having theritically knowledge of java,Kindly suggest me 

Java Beginners

java - Java Beginners
computer science i seem not to be understanding java quiet clearly i still fail to do simple programs what can i do , how can i understand java and how can i master programing , i can read a flow chart and do a program but the problem 

Java Beginners

Java
Java   Whether Java is pure object oriented Language 

Java Interview Questions

java
java  different between java & core java 

Java Beginners

java
java  explain technologies are used in java now days and structure java 

Java Interview Questions

java
java   why iterator in java if we for loop 

Java Beginners

JAVA
JAVA  how the name came for java language as "JAVA 

Java Beginners

java
java  what is java reflection 

Java Beginners

java
java  is java open source 

Java Interview Questions

java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java 

Java Interview Questions

java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception 

Java Beginners

Access and Java - Java Beginners
with the information from the employee's tax card: Tax is deducted each month in certain... the employee records in EXCESS and convert it to JAVA programing with solid and simple java codes 

Java Beginners

output java - Java Beginners
. This link will help you . Please visit : http://www.roseindia.net/java/master-java/index.shtml Thanks Amardeep...; } a. what is the output of the ff. java statement:? i. System.out.println (secret 

Java Beginners

java - Java Beginners
/java/master-java/java-object-oriented-language.shtml Thanks 

JSP Servlet Questions

Shoping Card
Shoping Card  Complete coding for online shoping card 

Java Beginners

Object in java - Java Beginners
. For read more information on Java OOPs visit to : http://www.roseindia.net/java/master-java/java-object-oriented-language.shtml http...Object in java  Hi deepak, I am new to java, can u tell me what 

Java Beginners

want to get job on java - Java Beginners
://www.roseindia.net/java/quick-java.shtmlhttp://www.roseindia.net/java/master-java/index.shtmlhttp://www.roseindia.net/java/master-java/java-a-general-purpose...want to get job on java  want to get job on java what should 

Java Beginners

java
java  write a java program using filenotfoundexception 

Java Beginners

Java
Java  how to draw class diagrams in java 

Java Beginners

java
java   difference between class and interface 

Java Interview Questions

java
java  why multiple inheritance is not possible in java 

Java Interview Questions

java
java  explain object oriented concept in java 

Java Interview Questions

java
java  is java purely object oriented language 

Java Beginners

Java
Java   Whether Java is Programming Language or it is SOftware 

Java Beginners

java
java  what are JAVA applications development tools 

Java Beginners

java
java  how use java method 

Java Interview Questions

java
java  send me java interview questions 

Advertisements Advertisements
 

 

 

DMCA.com