Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program 1: Card Game Make sure you include this ID as a System.out.println() message at the beginning of your program. This helps us with grading,

Program 1: Card Game

Make sure you include this ID as a System.out.println() message at the beginning of your program. This helps us with grading, and is required.

Description:

The 7.4 Case Study in the Textbook may be helpful.

We have a skeleton code on Canvas called CardGame.java. It would be a good idea to look at it and use it.(Its down below)

Notes: Pseudocode is only needed for certain methods. These are explained in the skeleton code. You need minimum 3 methods. You need to use loops for manipulating arrays. Do not use 50+ if statements to work on arrays. This will be counted against the Logic section in the rubric.

This post lab is broken up into 2 parts. Each will be its own method, and the choices will be collected from the main. Loop allowing the user to input part 1 or 2 as much as they want. If they enter -1, then end the program.

Part 1:

Based on what you learned in the lab, make a card game that asks the user to pick a number from a normal shuffled 52 card deck. Next, the computer picks a random number between 0 to 51. The program should then display whose card was highest.

Part 2:

As a second part to the program, create an auto play mode, where two computers play against each other. Like the first part, each computer randomly picks a card and a message declares the one with the highest card.

Have the deck shuffled every turn, and allow the two computers to play 100 times before quitting. Once they have played 100 times, display the winner of the whole game (who had the most wins out of 100 turns), or if it ended in a draw.

Have each part in its own separate method note that they should both be in a single class - and allow the user to choose between Part 1 or Part 2, for testing purposes. The main method should handle the input (getting the user choices) and call the methods.

Below is the input and the output we expect from your program. This is to help you know if you are on the right track. To test this Post Lab we might enter 6,8.7,34, 4.44, ect

Example input :

1

34

2

-1

Example output:

ID001

What part do you want to do? [integer]

Enter a card location from 0 to 51: [integer]

Computer chose: 2

You had a Queen of Spades!

Computer has a Ace of Diamonds

Computer had a higher card

What part do you want to do? [integer]

Computer 1 had a higher card: 2 of Diamonds

Computer 1 had a higher card: Queen of Spades

Tie

Computer 2 had a higher card: Queen of Clubs

[This goes on for 100 times]

Computer 1 had 53 wins

Computer 2 had 40 wins

Computer 1 won the game

What part do you want to do? [integer]

Goodbye!

/**

* @author (You need to add your name)

* @version

*

* Description:

*

*

* Pseudocode for:

*

* shuffleDeck Method

* declareWinner Method

* makeDeck method

*

*/

public class CardGame {

public static void main(String[] args) {

System.out.println("ID001");

String[] deck=makeDeck();

String [] sDeck=shuffleDeck(deck);

// loop {

// Ask the user which part they want to do

// if the user chooses part 1 {

// get the user choice and the computer's choice

// Make sure the choices are valid. The user should not

// be able to enter card 150000.

// Get the value of the card from each choice. Note

// that the deck should be SHUFFLED. So if the human

chooses card

// card 34, and the computer chooses card 2, the computer

// still might have a higher value card

// Your goal is to have the value of the card the human

chose

// and have a value of the card the computer chose.

// You should be able to pass in the deck array display

// the card suits and ranks

declareWinner(humanCardValue, computerCardValue, deck);

// } else {

// since the user chose part 2

// loop a hundred times {

// get the winner for both computers for each round

// NOTE: HOW DOES THE PROGRAM KNOW WHO WON?

// do you need to change the declareWinner method?

// Will it need to return anything? And how?

// Collect the number of wins for each

// }

// Display the number of wins for each and who won.

// }

// }

}

public static String[] makeDeck(){

String[] suits={"hearts","spades","clubs","diamonds"};

String[]rank={"Ace","2","3","4","5","6","7","8","9","10","Jack","Q

ueen","King"};

// You have the suits and the rank,

// How do you put them as strings?

// How do you easily make all the combinations of them?

return sortedDeck;

}

public static String[] shuffleDeck(String [] deck){

String[] shuffled=new String[52];

// You need to shuffle the array

return shuffled;

}

// Some kind of declareWinner method {

// Question you should ask:

/*

Does this need to return the results or can I just

display the results in here?

The values of the cards are strings. If the corresponding

string in the sorted deck is lower, then the corresponding string

from the computer's then who do you think has the higher value

card?

*/

//}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

What is a business plan?

Answered: 1 week ago