Question: Hello, This Question is from the book Object-Oriented Data Structures Using Java Third Edition. This Question is on page 381 and is Question 45. Solitaire:
Hello,
This Question is from the book Object-Oriented Data Structures Using Java Third Edition. This Question is on page 381 and is Question 45.
Solitaire: For this console-based application you should use GlassQueue. Use the RankCardDeck class from Section 5.5 to create a deck of cards. Also create three queues of cards called a b and c. randomly deal the cards to each of the queue as though the deck was shuffled, do this until each queue has ten cards. the amount of money the user has should be displayed before each round. The user starts with $30. The card values at the front of queues A and C are displayed to the user. they should have a ? in-between. The user must bet anything between $10 and total money that the ? will be in-between the other two cards (ties do not count so for example, 3 is not in-between 3 and 5; if the two cards displayed happen to have the same rank value theb they will lose the round monster what.) the program should then display the same numbers from a and c but this time the ? is going to be the top of the B. If that card is in between the other two cards, he or she wins and the player double what they bet. then a new round starts. Play continues for 10 rounds or until the player runs out of money. also at the beginning of each round display the round number.
Classes:
package support; import java.util.Random; public class RankCardDeck { private static final int numCards = 52; protected int[] carddeck = new int[numCards]; protected int curCardPos = 0; // position of the next card to be dealt protected Random rand = new Random(); // to generate random numbers public RankCardDeck() { for (int i = 0; i < numCards; i++) carddeck[i] = i / 4; // there are 4 cards of each rank } public void shuffle() // Randomizes the order of the cards in the deck and resets the // position of the current card to card 0. { int randLoc; // random location in card deck int temp; // for swap of cards for (int i = (numCards - 1); i > 0; i--) { randLoc = rand.nextInt(i); // random integer between 0 and i - 1 temp = carddeck[randLoc]; carddeck[randLoc] = carddeck[i]; carddeck[i] = temp; } curCardPos = 0; } public boolean hasMoreCards() // Returns true if there are still cards left to be dealt; // otherwise, returns false. { return (curCardPos != numCards); } public int nextCard() // Precondition: curCardPos != numCards // // Models a card being dealt by returning an integer representing // its rank and incrementing the position of the current card. { curCardPos = curCardPos + 1; return (carddeck[curCardPos - 1]); } } GlassQueue:
package ch05.queues;
public class GlassQueue
public GlassQueue() { super(); }
public GlassQueue(int origCap) { super(origCap); }
public int size() // Returns the number of elements in this queue. { return numElements; } public T peekFront() // Returns the object at the front of this queue. // If the queue is empty, returns null. { return queue[front]; } public T peekRear() // Returns the object at the rear of this queue. // If the queue is empty, returns null. { return queue[rear]; } }
I was looking for help on this question. Thank you.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
