A Deck of Cards - JAVA Task Details In this task you need to develop two classes: Card, for storing a single playing car

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

A Deck of Cards - JAVA Task Details In this task you need to develop two classes: Card, for storing a single playing car

Post by answerhappygod »

A Deck of Cards - JAVA
Task Details
In this task you need to develop two classes:
Card, for storing a single playing card (like the ace of
spades).
Deck, for storing a complete deck of 52 cards.
The Card class
We have started you off with the skeleton of the Card class,
your job is to complete this class so that it has the following
methods:
A constructor that accepts two parameters: a char value that
represents which suit the card belongs to, and an int value
representing the rank of the card within the suit. You can assume
that the suit will be one of the four special characters ♣, ♠ , ♦,
or ❤. You can also assume that the rank will be a number between 1
(corresponding to the ace), and 13 (corresponding to the king).
A getSuit method, which takes no parameters and returns the suit
of the card (as a char).
A getRank method, which takes no parameters and returns the rank
of the card (as an int).
A toString method, which takes no parameters and returns a
string representing both the rank and suit of the card. For numeric
cards, this string should simply contain both the rank and suit
without any other punctuation (e.g. 2♦, 10♠). For face cards, the
rank should be represented as a single capital letter (.e.g. A❤,
J♣, Q♠, K♦).
All of these methods should be public and not static. There
should not be any other public methods or properties, but you are
welcome to add any private properties and methods that you feel are
necessary/helpful.
The Deck class
An empty Deck class has been provided for you to complete with
the following methods:
A constructor that accepts no parameters, and populates the deck
with all 52 playing cards (no jokers). The playing cards should
initially be in a sequence where the suits are in the order ♣, ♠ ,
♦, ❤ and within each suit the cards should be ordered from ace
through to king.
A getSize method that takes no parameters and returns the number
of cards remaining in the deck. When the deck is first constructed,
this should equal 52. As cards are removed from the deck this
number should decrease.
A takeFromTop method that takes no parameters and returns the
first card from the deck, removing it from the deck and reducing
the size of the deck by one. For a new unshuffled deck, the first
call to this method should return the ace of clubs, followed by the
two of clubs, and so on.
A putOnBottom method that takes a card as the only parameter,
and returns a boolean. If the given card is not already in the
deck, this method should add the card to the end of the deck
(causing it to grow in size by 1) and return true. If the
given card is already in the deck, then calling this method should
return false, and not have any effect on the deck.
A shuffle method that takes no parameters and returns no values.
After calling this method the order of cards in the deck should be
randomised, such that it is not possible to predict which card will
be returned when calling takeFromTop. After calling this method the
deck should still contain the same cards (and thus the same total
number of cards) but they should be in a different order.
All of these methods should be public and not static.
You should not add any other public methods or properties, but you
are welcome to add any private properties and methods that you feel
are necessary/helpful.
The runner class
We have provided a Runner class with a main method that will be
executed when you click the Run button. You are welcome to
change this method however you like. This file is not used in
testing and is provided purely to allow you to interact with and
explore your own code.
Code Skeletons:
public class Deck {
//Your code here

}
//////////////////////////////////////////
public class Card {
public static final char[] SUITS =
{'♣','♠','♦','❤'};
public static final String[] RANKS =
{"A","2","3","4","5","6","7","8","9","10","J","Q","K"} ;
//Your code here
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply