The program will be divided into 3 files maincpp playerh and

The program will be divided into 3 files: main.cpp, player.h, and player.cpp player.h: This header file will contain the following organization sections (Separate all sections by use of comments // or /* */) 1) Library inclusions: Instead of putting all of the libraries and “using namespace std;” required in main, we will include them here and include “player.h” in main.cpp. 2) Constants: Create constants (symbolic or other) for the following: Cards per standard deck of cards = 52 Face variations per deck of cards = 13 Suit variations per deck of cards = 4 Maximum Number of cards in the player’s hand = 10 3) Card structure: Create a structure of card that (at minimum) contains the elements: string face; string suit; 4) Functions to handle the functionality of the deck of cards: card getTopCard(card *deck, int size) void shuffle(card *deck, int size) 5) The class Player including members and member function prototypes: Members – the members of this class should include the first and last name (separate) of the player, the amount of money the player has to use in a bet, the hand of cards, as well as the score. All members should be contained in the private section of the class. The hand of cards should be made as an array of structure card type set to the Maximum Number of cards in the player’s hand constant. Member Functions – the member functions in this class should include Constructors, Accessors, and Mutators in order to make this class functional. Function prototypes should include (at a minimum) all of the prototypes listed below. All member functions should be contained in the public section of the class. void addCard(card) void calculateScore(); void displayInfo(); double getCash() string getFirstName() string getLastName() int getScore(); Player() Player(string, string, int, double) void setCash(double) void setFirstName(string) void setLastName(string) void showHand() In the class, organize the member functions by Constructors, Accessors, and Mutators by use of comments. player.cpp: This is where all of the functions (prototyped in player.h) are implemented. Separate the structure functions and the Player functions by use of comments ( // or /* */) See Appendix for function descriptions. main.cpp: This is the test bench for your player.h and player.cpp files. In this file, the program will: Ask for the number of decks you want to shuffle. Ask for the number to seed for srand() Asks for the number of the cards to deal to the hand – checks to see if this value is between 1 and the maximum number of cards in the player’s hand. If the value is not between these two values, asks again until a proper number is given. Seeds srand() with the value given. Creates an array of cards (structure type card) of a size that equals to the number of decks times the number of cards per deck (constant in player.h) Shuffles the deck of cards Creates an object of player class and sets the first name and last name to your name, the starting score to 300, and the starting money to 1000. Displays the user info Adds cards to the user in a ‘for’ loop. Also shows the hand and calculated score for each new card added. The loop continues until the number of cards specified by the user is met. Sample Output: The sample output does not have to be identical to the output here, BUT the output must be organized and readable. Also, the suit can be displayed in letter format (H, S, D, C) or (,, , )

Each card you draw is te score. For examle if I am drawing 3 cards my first one is 7 the score is 7, my seconde is 10 the score is 7+10 = 17 te last one is Ace score becomes 7+10+1= 18

Solution

import javafx.scene.image.*; public class Card implements Comparable{ private static final String IMAGE_FOLDER_DIR = \"image\"; private static final String IMAGE_FORMAT = \".png\"; private static final String BACK_IMAGE_DIR = (\"image/back_image.png\"); private Image cardImage; private Image backImage; private SuitEnum suit; private RankEnum rank; public Card(){ } public Card(SuitEnum suit, RankEnum rank){ this.suit = suit; this.rank = rank; String location = generateImageLocation(); try { cardImage = new Image(location); } catch (Exception ex) { System.out.println(String.format(\"cannot load image from: (%s)\", location)); cardImage = null; } try { backImage = new Image(BACK_IMAGE_DIR); } catch (Exception ex){ System.out.println(String.format(\"cannot load image from: (%s)\", BACK_IMAGE_DIR)); backImage = null; } } public SuitEnum getSuit() { return suit; } public RankEnum getRank() { return rank; } public Image getCardImage(){ return cardImage; } private String generateImageLocation(){ StringBuilder sb = new StringBuilder(); sb.append(IMAGE_FOLDER_DIR); sb.append(\"/\"); sb.append(suit.toString()); sb.append(\"_\"); sb.append(rank.toString()); sb.append(IMAGE_FORMAT); return sb.toString().toLowerCase(); } @Override public String toString(){ return (suit + \" \" + rank); } public int compareTo(Card card) { if (this.rank.compareTo(card.rank) > 0){ return 1; } else if (this.rank.compareTo(card.rank) < 0){ return -1; } else { if(this.suit.compareTo(card.suit) > 0){ return 1; } else if (this.suit.compareTo(card.suit) < 0){ return -1; } else { return 0; } } } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((rank == null) ? 0 : rank.hashCode()); result = prime * result + ((suit == null) ? 0 : suit.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Card other = (Card) obj; if (rank != other.rank) return false; if (suit != other.suit) return false; return true; } public Image getBackImage() { return backImage; } import java.util.ArrayList; import java.util.Random; public class Deck { private ArrayList deck = new ArrayList<>(); public Deck(){ for (SuitEnum suit: SuitEnum.values()){ for (RankEnum rank : RankEnum.values()){ deck.add(new Card(suit, rank)); } } } //shuffle deck public void shuffle(){ ArrayList tempOldDeck = new ArrayList<>(); for (Card card: deck){ tempOldDeck.add(card); } int[] randomPermutation = generateRandomPermutation(deck.size()); for (int i = 0; i < deck.size(); i++){ deck.set(i, tempOldDeck.get(randomPermutation[i] - 1)); } } private int[] generateRandomPermutation(int high){ return generateRandomPermutation(1, high); } private int[] generateRandomPermutation(int low, int high){ ArrayList unselectedNumber = new ArrayList<>(); for (int i = low; i <= high; i++){ unselectedNumber.add(i); } Random rng = new Random(); int[] randomPermutation = new int[high - low + 1]; for (int i = 0; i < randomPermutation.length; i++){ int randomIndex = rng.nextInt(unselectedNumber.size()); randomPermutation[i] = unselectedNumber.get(randomIndex); unselectedNumber.remove(randomIndex); } return randomPermutation; } //draw top most public Card draw() throws EmptyDeckException{ if (deck.size() > 0){ Card drawnCard = deck.get(deck.size() - 1); deck.remove(deck.size() - 1); return drawnCard; } else throw new EmptyDeckException(); } //get deck size public int size(){ return deck.size(); } } public class EmptyDeckException extends Exception{ public EmptyDeckException(){ } public EmptyDeckException(String message){ super(message); } public EmptyDeckException(Throwable cause){ super(cause); } public EmptyDeckException(String message, Throwable cause){ super(message, cause); } }
The program will be divided into 3 files: main.cpp, player.h, and player.cpp player.h: This header file will contain the following organization sections (Separa
The program will be divided into 3 files: main.cpp, player.h, and player.cpp player.h: This header file will contain the following organization sections (Separa

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site