øving3
This commit is contained in:
@@ -8,57 +8,62 @@ package oving3.card;
|
||||
*/
|
||||
public class Card {
|
||||
|
||||
// TODO: Add fields here
|
||||
private char suit;
|
||||
private int face;
|
||||
|
||||
/**
|
||||
* The constructor of the {@code Card} class initializes the suit and face of
|
||||
* the card with the
|
||||
* first and second arguments, respectively.
|
||||
*
|
||||
* @param suit the suit of the card, one of {@code 'S'} (spades), {@code 'H'}
|
||||
* (hearts),
|
||||
* {@code 'D'} (diamonds), or {@code 'C'} (clubs)
|
||||
* @param face the face of the card, an integer between {@code 1} (ace) and
|
||||
* {@code 13} (king)
|
||||
* (both inclusive)
|
||||
* @throws IllegalArgumentException if the suit or face is illegal
|
||||
*
|
||||
* @see CardTest#testConstructor()
|
||||
*/
|
||||
public Card(char suit, int face) {
|
||||
// TODO: Implement this constructor
|
||||
}
|
||||
/**
|
||||
* The constructor of the {@code Card} class initializes the suit and face of
|
||||
* the card with the
|
||||
* first and second arguments, respectively.
|
||||
*
|
||||
* @param suit the suit of the card, one of {@code 'S'} (spades), {@code 'H'}
|
||||
* (hearts),
|
||||
* {@code 'D'} (diamonds), or {@code 'C'} (clubs)
|
||||
* @param face the face of the card, an integer between {@code 1} (ace) and
|
||||
* {@code 13} (king)
|
||||
* (both inclusive)
|
||||
* @throws IllegalArgumentException if the suit or face is illegal
|
||||
*
|
||||
* @see CardTest#testConstructor()
|
||||
*/
|
||||
public Card(char suit, int face) {
|
||||
if (suit != 'S' && suit != 'H' && suit != 'D' && suit != 'C') {
|
||||
throw new IllegalArgumentException("Illegal value for suit");
|
||||
}
|
||||
if (face < 1 || face > 13) {
|
||||
throw new IllegalArgumentException("Illegal value for face");
|
||||
}
|
||||
this.suit = suit;
|
||||
this.face = face;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suit of the card
|
||||
*/
|
||||
public char getSuit() {
|
||||
// TODO: Implement this method
|
||||
return '\0';
|
||||
}
|
||||
/**
|
||||
* @return the suit of the card
|
||||
*/
|
||||
public char getSuit() {
|
||||
return suit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the face of the card
|
||||
*/
|
||||
public int getFace() {
|
||||
// TODO: Implement this method
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* @return the face of the card
|
||||
*/
|
||||
public int getFace() {
|
||||
return face;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value of the card of the form {@code <suit><face>}. For example,
|
||||
* the ace of
|
||||
* spades should return {@code "S1"}
|
||||
*
|
||||
* @see CardTest#testToString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO: Implement this method
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @return the value of the card of the form {@code <suit><face>}. For example,
|
||||
* the ace of
|
||||
* spades should return {@code "S1"}
|
||||
*
|
||||
* @see CardTest#testToString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return suit + Integer.toString(face);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user