A deck of cards contains 52 cards with four suits: club, diamond, heart and spade ranging in values from 2, ... to 10, Jack, Queen, King and Ace. Ace has the highest value in the same suit. Cards can be compared using the face value. A card with higher face value is bigger than a card with lower face value. If two cards have the same face value, then the suit determines the order. Club is smaller than diamond which is smaller than heart which is smaller than spade. For example: club 2 < diamond 2 < heart 2 < spade 2 if compared. Write an interactive Java program that allows a user to randomly pick a card from the deck of 52 cards (using a random number between 1 and 4 to represent the four suits: club, diamond, heart and spade and then another random number to represent the face value) to play. Show the suit and face value of the user card. Then the program acts as a card dealer which randomly draws another card and displays the card (again showing the suit and face value of the card). Your program then compares the two cards’ face values and suits if the two cards have the same face values, and displays the result: you win, or you lose. Note that it is impossible to have a tie. You can use an array called card with 15 elements to hold the 13 cards in the selected suit. The index of each array element can represent the face value of a card (from 2 to 14, note that the first two elements card [0], and card[1] are not used). For example, card[2] represents the card with face value 2, card[8] represents card with face value 8 and card[14] represents the card with face value Ace etc. The value stored in each array element is either 1 (true) or 0 (false) representing whether a particular card has been drawn or not. It is better (not required) to define a method that randomly draws a card and returns the card’s value it draws. Keep in mind, once a card is drawn from the suit, it cannot be drawn again. This requires that you need to first check if the array element representing the card is 0 or 1. Only returns the card value and suit if the array element contains 0. You have to set its value to 1 before returning the card value and suit to the calling program. Your program first displays a message telling the user the playing instructions, then it calls the drawing method to draw a card for you and display the result, After that it calls the drawing method again to draw a card for computer and displays the result. Finally, your program compares two cards and displays the result. After one play, your program asks the user if he/she wants to continue playing the same deck of cards or to shuffle the cards which means to start with a new deck. Shuffling a deck of cards means your program reset the card array elements to 0. Note that if a user chooses to continue playing with the same deck of cards, he/she can only play 26 games since each game uses 2 cards and there are 52 cards in a deck. You need to have a counter to count to make sure that you won’t get into an infinite loop when drawing a card. When finished, your program displays total number of games played, number of times the user wins and the number of time computer wins.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%
A deck of cards contains 52 cards with four suits: club, diamond, heart and spade ranging in values from 2, ... to 10, Jack, Queen, King and Ace. Ace has the highest value in the same suit. Cards can be compared using the face value. A card with higher face value is bigger than a card with lower face value. If two cards have the same face value, then the suit determines the order. Club is smaller than diamond which is smaller than heart which is smaller than spade. For example: club 2 < diamond 2 < heart 2 < spade 2 if compared. Write an interactive Java program that allows a user to randomly pick a card from the deck of 52 cards (using a random number between 1 and 4 to represent the four suits: club, diamond, heart and spade and then another random number to represent the face value) to play. Show the suit and face value of the user card. Then the program acts as a card dealer which randomly draws another card and displays the card (again showing the suit and face value of the card). Your program then compares the two cards’ face values and suits if the two cards have the same face values, and displays the result: you win, or you lose. Note that it is impossible to have a tie. You can use an array called card with 15 elements to hold the 13 cards in the selected suit. The index of each array element can represent the face value of a card (from 2 to 14, note that the first two elements card [0], and card[1] are not used). For example, card[2] represents the card with face value 2, card[8] represents card with face value 8 and card[14] represents the card with face value Ace etc. The value stored in each array element is either 1 (true) or 0 (false) representing whether a particular card has been drawn or not. It is better (not required) to define a method that randomly draws a card and returns the card’s value it draws. Keep in mind, once a card is drawn from the suit, it cannot be drawn again. This requires that you need to first check if the array element representing the card is 0 or 1. Only returns the card value and suit if the array element contains 0. You have to set its value to 1 before returning the card value and suit to the calling program. Your program first displays a message telling the user the playing instructions, then it calls the drawing method to draw a card for you and display the result, After that it calls the drawing method again to draw a card for computer and displays the result. Finally, your program compares two cards and displays the result. After one play, your program asks the user if he/she wants to continue playing the same deck of cards or to shuffle the cards which means to start with a new deck. Shuffling a deck of cards means your program reset the card array elements to 0. Note that if a user chooses to continue playing with the same deck of cards, he/she can only play 26 games since each game uses 2 cards and there are 52 cards in a deck. You need to have a counter to count to make sure that you won’t get into an infinite loop when drawing a card. When finished, your program displays total number of games played, number of times the user wins and the number of time computer wins.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY