Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class Deck {
- // Variables
- ArrayList <Card> downCards;
- // Constructor
- Deck(){
- downCards = new ArrayList <Card> ();
- }
- // Methods
- public void showStatus(){
- System.out.println("******** DECK STATUS: ********");
- for(int i=0; i<downCards.size(); i++){
- System.out.print(downCards.get(i).abbreviation + ", ");
- }
- }
- public void display(){
- for(int i=0; i<downCards.size(); i++){
- System.out.print(downCards.get(i).abbreviation + " # ");
- }
- System.out.println();
- }
- public void addCardInDeck(Card card){
- downCards.add(card);
- }
- public void addCardsInDeck(ArrayList <Card> cards){
- for(int i=0; i<cards.size(); i++){
- downCards.add(cards.get(i));
- }
- }
- public ArrayList <Card> removeAllCardsFromDeck(){
- ArrayList <Card> returnedList = new ArrayList <Card> ();
- returnedList = (ArrayList <Card>) downCards.clone();
- downCards.clear();
- return returnedList;
- }
- // MAIN METHOD
- public static void main(String[] args) {
- Deck deck = new Deck();
- // Create a list of cards
- Card card1 = new Card("1", "heart");
- Card card2 = new Card("2", "club");
- Card card3 = new Card("3", "diamond");
- Card card4 = new Card("4", "spade");
- ArrayList <Card> deckCards = new ArrayList <Card> ();
- deckCards.add(card1);
- deckCards.add(card2);
- deckCards.add(card3);
- deckCards.add(card4);
- deck.addCardsInDeck(deckCards);
- deck.showStatus();
- System.out.println();
- System.out.println();
- System.out.println("******** After remove method ********");
- ArrayList <Card> removed = deck.removeAllCardsFromDeck();
- System.out.println("List named 'removed' has these cards: ");
- for(int i=0; i<removed.size(); i++){
- System.out.println(removed.get(i).abbreviation);
- }
- System.out.println();
- deck.showStatus();
- } // END OF MAIN
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement