Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- public class CardsPack {
- // Variables
- ArrayList <Card> cards;
- // Constructor
- CardsPack(){
- cards = new ArrayList <Card> ();
- // 1. Add the "heart" cards
- for(int i=0; i<10; i++){
- Card card = new Card(Integer.toString(i+1), "heart");
- cards.add(card);
- }
- cards.add(new Card("J", "heart"));
- cards.add(new Card("Q", "heart"));
- cards.add(new Card("K", "heart"));
- // 2. Add the club" cards
- for(int i=0; i<10; i++){
- Card card = new Card(Integer.toString(i+1), "club");
- cards.add(card);
- }
- cards.add(new Card("J", "club"));
- cards.add(new Card("Q", "club"));
- cards.add(new Card("K", "club"));
- // 3. Add the "diamond" cards
- for(int i=0; i<10; i++){
- Card card = new Card(Integer.toString(i+1), "diamond");
- cards.add(card);
- }
- cards.add(new Card("J", "diamond"));
- cards.add(new Card("Q", "diamond"));
- cards.add(new Card("K", "diamond"));
- // 4. Add the "spade" cards
- for(int i=0; i<10; i++){
- Card card = new Card(Integer.toString(i+1), "spade");
- cards.add(card);
- }
- cards.add(new Card("J", "spade"));
- cards.add(new Card("Q", "spade"));
- cards.add(new Card("K", "spade"));
- }
- // Methods
- public void showStatus(){
- for(int i=0; i<cards.size(); i++){
- System.out.println("Card " + (i+1) + ": " + cards.get(i).value + " of " + cards.get(i).symbol + "s");
- }
- }
- public void display(){
- for(int i=0; i<cards.size(); i++){
- cards.get(i).display();
- System.out.print(" ");
- }
- }
- public void shuffle(){
- Collections.shuffle(cards);
- Collections.shuffle(cards);
- }
- // ********************************************************************************************************
- // ********************************************************************************************************
- // USEFUL METHODS WHILE PLAYING
- public Card returnFirstCard(){
- return cards.get(0);
- }
- public void removeFirstCard(){
- cards.remove(cards.get(0));
- }
- public ArrayList <Card> returnFirstNCards(int N){
- ArrayList <Card> returnedList = new ArrayList <Card> ();
- for(int i=0; i<N; i++){
- returnedList.add(cards.get(i));
- }
- return returnedList;
- }
- public void removeFirstNCards(int N){
- for(int i=0; i<N; i++){
- cards.remove(cards.get(i));
- }
- }
- // ********************************************************************************************************
- // ********************************************************************************************************
- // MAIN FUNCTION
- public static void main(String[] args) {
- System.out.println("******** Not a shuffled cards pack ********");
- CardsPack trapoula = new CardsPack();
- trapoula.showStatus();
- trapoula.display();
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println("******** A shuffled cards pack ********");
- trapoula.shuffle();
- trapoula.showStatus();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement