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

Complete the MindTap Chapter 7 Accumulating Totals in a Single Level Conti Pytho

ID: 3572097 • Letter: C

Question

Complete the MindTap Chapter 7 Accumulating Totals in a Single Level Conti Python lab J Chapter 7 programming assignment Use your chapter 6 deck of cards assignment Write each card of your shuffled deck to a file named shuffledDeck.dat Read each card in a loop and display the card to the console The user should be able to hit the enter key to see the next card End the loop when all cards have been dealt Allow the user to shuffle again and output or quit the program. Name your program shuffledDeck.py ZIP all your files into a file name program5.zip and upload to Moodle

Explanation / Answer

public class Deck {

    public static void main(String[] args) {

        String[] SUITS = {

            "Clubs", "Diamonds", "Hearts", "Spades"

        };

        String[] RANKS = {

            "2", "3", "4", "5", "6", "7", "8", "9", "10",

            "Jack", "Queen", "King", "Ace"

        };

        // initialize deck

        int n = SUITS.length * RANKS.length;

        String[] deck = new String[n];

        for (int i = 0; i < RANKS.length; i++) {

            for (int j = 0; j < SUITS.length; j++) {

                deck[SUITS.length*i + j] = RANKS[i] + " of " + SUITS[j];

            }

        }

        // shuffle

        for (int i = 0; i < n; i++) {

            int r = i + (int) (Math.random() * (n-i));

            String temp = deck[r];

            deck[r] = deck[i];

            deck[i] = temp;

        }

        // print shuffled deck

        for (int i = 0; i < n; i++) {

            System.out.println(deck[i]);

        }

    }

}

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