Question: /* * Card.java * * A blueprint class to represent an individual playing card. * * CS 112, Boston University * * completed by: ,

/*

* Card.java

*

* A blueprint class to represent an individual playing card.

*

* CS 112, Boston University

*

* completed by: ,

*/

public class Card {

// constants for the ranks of non-numeric cards

public static final int ACE = 1;

public static final int JACK = 11;

public static final int QUEEN = 12;

public static final int KING = 13;

// other constants for the ranks

public static final int FIRST_RANK = 1;

public static final int LAST_RANK = 13;

// Arrays of strings for the rank names and abbreviations.

// The name of the rank r is given by RANK_NAMES[r].

// The abbreviation of the rank r is given by RANK_ABBREVS[r].

private static final String[] RANK_NAMES = {

null, "Ace", "2", "3", "4", "5", "6",

"7", "8", "9", "10", "Jack", "Queen", "King"

};

private static final String[] RANK_ABBREVS = {

null, "A", "2", "3", "4", "5", "6",

"7", "8", "9", "10", "J", "Q", "K"

};

// constants for the suits

public static final int FIRST_SUIT = 0;

public static final int LAST_SUIT = 3;

public static final int CLUBS = 0;

public static final int DIAMONDS = 1;

public static final int HEARTS = 2;

public static final int SPADES = 3;

// Arrays of strings for the suit names and abbreviations.

// The name of the suit s is given by SUIT_NAMES[s].

// The abbreviation of the suit s is given by SUIT_ABBREVS[s].

private static final String[] SUIT_NAMES = {

"Clubs", "Diamonds", "Hearts", "Spades"

};

private static final String[] SUIT_ABBREVS = {

"C", "D", "H", "S"

};

/***** part 2: getSuitNum *****/

private static int getSuitNum(String suit) {

// The return statement below is included so the starter code

// will compile.

// Replace it with your implementation of the method.

public static

return 0;

}

/***** Implement parts 3-7 below. *****/

}

/* * Card.java * * A blueprint class to represent an individual

4. Implement the constructors (3 points) In Java, a class can have more than one constructor; this provides clients of the class with different options for creating a new object of the class. All of the constructors must be named after the class, but their parameter lists must differ from each other in some way. You should add the following two constructors to the Card class: . a constructor that takes two integer parameters specifying the card's rank and suit number (in that order). It should ensure that only valid values are assigned to the object's fields, as specified in part 3. a constructor that takes an integer parameter specifying the card's rank and a String parameter specifying the card's suit (in that order). Note that this constructor will need to determine the suit number for the specified suit string, and it should use another method that you have already written for this purpose. Here again, the constructor should ensure that only valid values are assigned to the object's fields. For example, here is some code that uses the constructors: Card c1 = new Card(1, 2); // Ace of Hearts Card c2 = new Card(5, 1); // 5 of Diamonds Card c3 new Card(12, "hearts"); // Queen of Hearts

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!