Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class (Solitaire), in Java, given the following: You are given a Solitai

ID: 643941 • Letter: W

Question

Write a class (Solitaire), in Java, given the following:

You are given a SolitaireTester class that uses Solitaire.

public class SolitaireTester { public static void main(String[] args) { Solitaire s = new Solitaire(); System.out.println("Start: " + s.toString()); int rounds = 0; while (!s.over()) { s.round(); ++rounds; System.out.println(rounds + ": " + s.toString()); } System.out.println("Rounds: " + rounds); } }

SolitaireTester produces a random starting configuration and prints it. Then keeps applying the solitaire step and prints the result. Stops when the solitaire final configuration is reached and prints the number of rounds.

The Solitaire class:

Constants as required

Exactly and only the following instance variable is required: private ArrayList piles;

constructor() Initialize piles to a random number of piles of random size, but exactly 45 cards total. Use Math.random() as you do this. random() returns a double value greater than or equal to 0.0 and less than 1.0. As an example, to set num to a random integer value between 1 and 10 inclusive is: num = (int) (Math.random() * 10) + 1;

toString() Return a string representation of a Solitaire object. To do this, simply: return piles.toString();

over() Return true if the solitaire is over, false otherwise. The solitaire is over when the piles have size 1, 2, 3, 4, 5, 6, 7, 8, and 9, in some order. (It can be shown that you always end up with such a configuration.)

round() In each round, you take one card from each pile, forming a new pile with these cards.

Explanation / Answer

01 import java.util.*; 02 import java.awt.*; 03 04 /** 05 * A full deck of cards. It is shuffled when first constructed 06 * and thereafter cards are removed from the deck by calls to 07 * nextCard until no further cards remain. Cards can also be 08 * placed back on the deck at either the start or the end. 09 */ 10 public class Deck 11 { 12    private java.util.List cards; // The list of cards 13    private static java.util.Random generator =null; 14       15    /** 16      * Constructor for a shuffled deck of cards. 17      * @param seed the seed for the random number generator used to 18      * shuffle the deck. A different unique shuffle is obtained for 19      * each possible value of seed. 20      */ 21    public Deck(long seed) 22    { 23    // Create a deck of cards in sorted order of suit then pip count. 24       25    cards = new ArrayList(); 26    for (int suit = Card.SPADES; suit
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote