This commit is contained in:
2026-02-09 17:03:32 +01:00
parent af8cbf6768
commit 8e08785db0
6 changed files with 187 additions and 49 deletions
+52 -47
View File
@@ -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) {
}
}
}