Advertisement
makispaiktis

CardsGame - Deck.java

Mar 17th, 2020 (edited)
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Deck {
  4.  
  5.     // Variables
  6.     ArrayList <Card> downCards;
  7.    
  8.     // Constructor
  9.     Deck(){
  10.         downCards = new ArrayList <Card> ();
  11.     }
  12.    
  13.     // Methods
  14.     public void showStatus(){
  15.         System.out.println("******** DECK STATUS: ********");
  16.         for(int i=0; i<downCards.size(); i++){
  17.             System.out.print(downCards.get(i).abbreviation + ", ");
  18.         }
  19.     }
  20.    
  21.     public void display(){
  22.         for(int i=0; i<downCards.size(); i++){
  23.             System.out.print(downCards.get(i).abbreviation + " # ");
  24.         }
  25.         System.out.println();
  26.     }
  27.    
  28.    
  29.    
  30.     public void addCardInDeck(Card card){
  31.         downCards.add(card);
  32.     }
  33.    
  34.     public void addCardsInDeck(ArrayList <Card> cards){
  35.         for(int i=0; i<cards.size(); i++){
  36.             downCards.add(cards.get(i));
  37.         }
  38.     }
  39.    
  40.     public ArrayList <Card> removeAllCardsFromDeck(){
  41.         ArrayList <Card> returnedList = new ArrayList <Card> ();
  42.         returnedList = (ArrayList <Card>) downCards.clone();
  43.         downCards.clear();
  44.         return returnedList;
  45.     }
  46.    
  47.    
  48.     // MAIN METHOD
  49.     public static void main(String[] args) {
  50.         Deck deck = new Deck();
  51.         // Create a list of cards
  52.         Card card1 = new Card("1", "heart");
  53.         Card card2 = new Card("2", "club");
  54.         Card card3 = new Card("3", "diamond");
  55.         Card card4 = new Card("4", "spade");
  56.         ArrayList <Card> deckCards = new ArrayList <Card> ();
  57.         deckCards.add(card1);
  58.         deckCards.add(card2);
  59.         deckCards.add(card3);
  60.         deckCards.add(card4);
  61.         deck.addCardsInDeck(deckCards);
  62.         deck.showStatus();
  63.         System.out.println();
  64.         System.out.println();
  65.         System.out.println("******** After remove method ********");
  66.         ArrayList <Card> removed = deck.removeAllCardsFromDeck();
  67.         System.out.println("List named 'removed' has these cards: ");
  68.         for(int i=0; i<removed.size(); i++){
  69.             System.out.println(removed.get(i).abbreviation);
  70.         }
  71.         System.out.println();
  72.         deck.showStatus();
  73.        
  74.     }   // END OF MAIN
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement