Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* * * HELP in JAVA * * * I feel like I ' m so close to getting it to work but I don't

***HELP in JAVA*** I feel like I'm so close to getting it to work but I don't know what to do with my objects to make it effective:Write a BlackJack program that plays a game of BlackJack.
The program must draw a card randomly from a standard deck of 52 cards.
Your program must not print the same card twice until the deck runs out.
Your program must shuffle the deck when if runs out of cards.
All cards should be added back to the deck when shuffle() is called.
Your program should produce different output every time it runs (Based on randomly selecting cards).
For simplicity, you can consider the BlackJack value of an Ace to be 11.
This is what I have so far:
//@author newToLife
public class Card{
//Use these class diagrams to create your objects.
private int value;
private String suit;
private String Color;
private String face;
public Card(){
}
public Card(int value, String suit){
this.value = value;
this.suit = suit;
}
@Override
public String toString(){
return face +" of "+ suit;
}
public String getColor(){
return Color;
}
public String getFace(){
return face;
}
public int getValue(){
return value;
}
public int getBjValue(){
int BJValue;
if(value >=2 && value<=10){
BJValue = value;
return BJValue;
}else
BJValue =11;
return BJValue;
}
public String getSuit(){
return suit;
}
}
//next file
public class Deck {
private ArrayList cards = new ArrayList<>();
private int deckSize =52;
public Deck(){
loadCards();
}
private void loadCards(){
for (int value =1; value <=13; value++){
for(String suit : new String[]{"hearts","diamonds","clubs", "spades"}){
Card card = new Card(value, suit);
cards.add(card);
}
}
shuffle();
}
public Card drawCard(){
if (deckSize ==0)
loadCards();
deckSize--;
return cards.remove(deckSize);
}
public int getDeckSize(){
return deckSize;
}
public void shuffle(){
java.util.Collections.shuffle(cards);
deckSize = cards.size();
}
}
//next file
import java.util.*;
import java.util.ArrayList;
public class BlackJack{ int bets;
int bank =500;
int hit;
int playAgain =0;
Deck gameDeck = new Deck();
Card gameCard = new Card();
int drawnCards =0;
int dealerTotal =0;
ArrayList bjDeck = new ArrayList<>();
Scanner input = new Scanner(System.in);
do{
System.out.println("Welcome to Blackjack you have $"+ bank);
System.out.println("Place your bets");
bets = input.nextInt();
System.out.println("Here are your 2 cards");
gameDeck.drawCard();
bjDeck.add(gameDeck);
gameDeck.drawCard();
bjDeck.add(gameDeck);
System.out.println(bjDeck.get(0)+""+ bjDeck.get(1));
System.out.println("Total is: "+ "add drawn cards");
System.out.println("Do you want a hit? 1= yes 2= no");
hit = input.nextInt();
if(hit ==1){
//draw another card and add to previous cards
//draw 2 dealer cards from the same deck and total them
System.out.println("Dealer Total "+ "total dealer cards");
if(dealerTotal <=21 && drawnCards >21){
System.out.println("Dealer Wins");
bank = bank - bets;
}
else{
System.out.println("Dealer Busted");
bank = bank + bets;
}
}
else if(hit ==2){
//draw 2 dealer cards from the same deck and total them
System.out.println("Dealer Total "+ "total dealer cards");
if(dealerTotal <=21 && dealerTotal > drawnCards){
System.out.println("Dealer Wins");
bank = bank - bets;
}
else{
System.out.println("Dealer Busted");
bank = bank + bets;
}
}
System.out.println("Your Bank: $"+ bank);
System.out.prin

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions

Question

What is group replacement? Explain with an example. (2-3 lines)

Answered: 1 week ago

Question

Organizing Your Speech Points

Answered: 1 week ago