Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In JAVA please. No JAVAFX In this project you will create a solution designed to play Blackjack. We will use simple rules of the game.

In JAVA please. No JAVAFX

In this project you will create a solution designed to play Blackjack. We will use simple

rules of the game. Assume there exists a player and a dealer. The winner of the game is

the player who gets closest to 21 without exceeding 21 or going bust. If both players

have the same points, then neither player wins the hand. An ace has a value of 1 or 11.

Face cards have a value of 10. The dealer must take a card if the dealers hand is worth

16 or less. The dealer may not take a card if the hand is worth 17 or more. As the player,

you may take a card at any time.

Allow the user to play as many hands as he/she wants.

Keep track of how many hands the dealer wins and how many hands the player wins.

How to get started;

Create a class called Card.

The card has three fields; a value , a suit and a face.

The card class has a constructor that takes three values for the three fields.

Create a no-args constructor.

The Card class has three get methods to return the values of each of the fields.

The Card class has a toString( ) method.

The Card class has a compareTo( ) method that uses the value of the card to determine

the ordering.

Create an equals( ) method that returns true if the parameter Card has the same suit and

the same face as the invoking Card.

Create a class called Deck.

A deck has two fields- an array of Cards and an int which

holds the subscript of the Card at the top of the deck.

The Deck class will have only one constructor, which will create the array. Try to think

of a way to code this without writing 52 statements. (not required)

The Deck class also has a method getTopCard( ) which returns a

copy

of the Card that is

at the top of the array.

The Deck class has a method called shuffle( ) which shuffles the array of Cards. To

shuffle, generate random numbers and use these to exchange array elements. Exchange

1000 times in this method

Create the driver class - call it Game21.

This is where your game logic will go. As a hint, you will need to create two Deck

instances and then call the shuffle method( ) for each. When you are testing as you write,

before you shuffle( ) you may want to print out the entire Deck to make sure you have

created the array of Cards correctly.

Each player is dealt two cards to start. Then the rules stated above are followed. Only the

user has the choice whether to deal another card or quit. The dealer (computer) must be

dealt another card from its deck if its total is 16 or under and must quit if its hand is 17 or

over.

Once a hand is won, either by the computer or the player, allow the player to decide if

he/she wants to play another hand. Keep a running total of the number of hands won by

the computer and the number of hands won by the player. Print these results to a file once

the user decides to quit. Each time the program is run, the results of the session should be

appended to the same output file.

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

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions