Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(PLEASE ANSWER THIS QUESTIONS ASAP,I NEED IT QUICKLY PLZ(IF YOU ARE WORKING ON THIS,CAN YOU TYPE WORKING IN THE COMMENT SECTION SO I KNOW YOU

(PLEASE ANSWER THIS QUESTIONS ASAP,I NEED IT QUICKLY PLZ(IF YOU ARE WORKING ON THIS,CAN YOU TYPE "WORKING" IN THE COMMENT SECTION SO I KNOW YOU ARE DOING IT)

For this assignment you are working for onlinegames.com and want to create a simple blackjack card game simulation.

You will first need to create a class called Card. Cards have 3 attributes:

String suit: possible values Hearts, Spades, Diamonds, Clubs

String rank: possible values Ace, Two through Ten, Jack, Queen, King

int value: 2 through 10 have value they show; Ace starts at 11; Jack, Queen, King are 10

Methods in Card:

  • Card(String s, String r, int v) constructor should initialize instance variables for Card

  • String getSuit() returns suit of card

  • String getRank() returns rank of card

  • int getValue() returns value of card

  • void setValue(int newvalue) updates the value of card (to be used with Aces) should check if current cards Rank is Ace and newValue is 1 or 11, if so make change

  • String toString() returns String to be printed in format: Ace of Spades

In CardGame.java:

  • main()

welcome the player and explain the rules

create the Deck

shuffle the Deck

deal 2 cards to player, deal 2 cards to computer (these would also be an ArrayList of Cards)

print players hand, print computers top card

total cards in Players hand and tells player their current total (use handValue method)

tell player computers top card Rank

if computer dealt 21, automatic win for computer, stop game

loop to ask player if they would like to hit or stay, if they stay stop

deal one card at a time to player, showing them the new hand and adding to their total

if they hit 21, stop and computers turn

if their total is over 21, check if they have an Ace worth 11 and switch to 1

if they bust game over, they lose, stop game

if player stays, add to computer hand following these directions:

if computer hand <=16, deal another card

if computer hand >21, computer loses

if computer hand = 21, computer wins

anything else stop to compare hands

if game not over yet, compare computer score and player score to declare winner (ties go in favor of computer)

  • ArrayList createDeck() fills the ArrayList of Cards

Create an array of Suits and an array of Ranks

Using embedded loops, fill the ArrayList of Cards with a standard 52 card deck (values go with ranks)

  • ArrayList shuffleDeck(ArrayList deck) shuffles the deck.

This should be done by creating a new ArrayList of cards and randomly choosing cards and removing cards from the deck to insert into the new ArrayList. Return the new ArrayList of cards and dont forget to store it in the original deck in main.

  • int handValue(ArrayList hand) totals and returns points of whichever hand method is passed

use this any time you want the players or computers total

Grading considerations, 45 out of 50 points:

Code is commented, including pre/post conditions before methods: 5 points

Card coded correctly 10 points

createDeck 5 points, shuffleDeck 5 points, handValue 5 points

gameplay in main

showing hands each turn: 5 points

following game rules: 5 points

declaring winner/loser/tie: 5 points

Optional add ons - pick one (5 points): more than one player, looping rounds of plays and keeping tally of wins/losses

Sample Run:

Welcome to BlackJack. The rules of the game are as follows:

// you fill this in

Your hand:

Player: {Seven of Spades, Ten of Hearts} total: 17

The computer has a Jack.

Do you want to hit or stay?

stay

The computers hand: {Jack of Diamonds, King of Clubs} total: 20

The computer wins.

Welcome to BlackJack. The rules of the game are as follows:

// you fill this in

Your hand:

Player: {Two of Diamonds, Six of Clubs} total: 8

The computer has a Nine.

Do you want to hit or stay?

hit

Player: {Two of Diamonds, Six of Clubs, Queen of Hearts} total: 18

Do you want to hit or stay?

stay

The computers hand: {Nine of Spades, Three of Hearts, Jack of Clubs} total: 22

The computer busts, you win!

Welcome to BlackJack. The rules of the game are as follows:

// you fill this in

Your hand:

Player: {Eight of Spades, Five of Clubs} total: 13

The computer has a Queen.

Do you want to hit or stay?

hit

Player: {Eight of Spades, Five of Clubs, Ten of Hearts} total: 23

You bust, computer wins!

Welcome to BlackJack. The rules of the game are as follows:

// you fill this in

Your hand:

Player: {Ten of Diamonds, Jack of Spades} total: 20

The computer has a Nine.

Do you want to hit or stay?

stay

The computers hand: {Nine of Hearts, Five of Clubs, Six of Spades} total: 20

Tie, Computer wins.

Welcome to BlackJack. The rules of the game are as follows:

// you fill this in

Your hand:

Player: {Two of Clubs, Eight of Diamonds} total: 10

The computer has a Seven.

Do you want to hit or stay?

hit

Player: {Two of Clubs, Eight of Diamonds, Queen of Diamonds} total: 20

The computers hand: {Seven of Clubs, Ten of Spades} total: 17

You win!

Take your time,this assignment is due on March 12th,so finish it by then.(PLEASE WRITE THIS CODE AS JAVA)

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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

Describe the two different gas flows in plasma arc welding.

Answered: 1 week ago

Question

7. What decisions would you make as the city manager?

Answered: 1 week ago

Question

8. How would you explain your decisions to the city council?

Answered: 1 week ago