jaredec18

Untitled

Sep 20th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.84 KB | None | 0 0
  1. //class cards, cards.java
  2.  
  3. package blackjackgame;
  4.  
  5. /**
  6.  
  7. *
  8.  
  9. * Cards suit and number
  10.  
  11. */
  12.  
  13. public class Cards {
  14.  
  15. private Suits cardSuit;
  16.  
  17. private int cardNum;
  18.  
  19. private String[] numString = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
  20.  
  21. /**
  22.  
  23. * Cards constructor
  24.  
  25. * @param sType
  26.  
  27. * @param sNum
  28.  
  29. */
  30.  
  31. public Cards(Suits stype, int snum){
  32.  
  33. this.cardSuit = stype;
  34.  
  35. if(snum >=1 && snum <= 13)
  36.  
  37. this.cardNum = snum;
  38.  
  39. else{
  40.  
  41. System.err.println(snum+" is not a valid card number\n");
  42.  
  43. System.exit(1);
  44.  
  45. }
  46.  
  47. }
  48.  
  49. public int getCardNumber(){
  50.  
  51. return this.cardNum;
  52.  
  53. }
  54.  
  55. public String toString(){
  56.  
  57. return this.numString[this.cardNum - 1]+" of "+this.cardSuit.toString();
  58.  
  59. }
  60.  
  61. }
  62.  
  63. //class deck, deck.java
  64.  
  65. package blackjackgame;
  66.  
  67. import java.util.Random ;
  68.  
  69. /**
  70.  
  71. * Deck of cards-- forming a dynamic deck
  72.  
  73. * 1 Pack = 52 cards;
  74.  
  75. * Deck = one or more packs;
  76.  
  77. *
  78.  
  79. */
  80.  
  81. public class Deck {
  82.  
  83. // cards in the deck --- arraylist or linkedlist could also be used
  84.  
  85. private Cards[] cardsInDeck;
  86.  
  87. private int numOfCardsInDeck;
  88.  
  89. private int onePack = 52;
  90.  
  91. /**
  92.  
  93. * constructor for default shuffled deck consisting of 1 pack i.e 52 cards
  94.  
  95. */
  96.  
  97. public Deck(){
  98.  
  99. this(1, true);
  100.  
  101. }
  102.  
  103. /**
  104.  
  105. *
  106.  
  107. * Deck constructor to define number of cards in a Deck && whether it should be shuffled or not
  108.  
  109. *
  110.  
  111. * @param numPacks
  112.  
  113. * @param shuffle
  114.  
  115. */
  116.  
  117. public Deck(int numPacks, boolean shuffle){
  118.  
  119. this.numOfCardsInDeck = numPacks*this.onePack;
  120.  
  121. this.cardsInDeck = new Cards[this.numOfCardsInDeck];
  122.  
  123. int c = 0;
  124.  
  125. // for each deck
  126.  
  127. for(int d=0;d<numPacks;d++){
  128.  
  129. // for each suit
  130.  
  131. for(int s=0; s<4;s++){
  132.  
  133. // for each number
  134.  
  135. for(int n=1;n<=13;n++){
  136.  
  137. this.cardsInDeck[c] = new Cards(Suits.values()[s], n);
  138.  
  139. c++;
  140.  
  141. }
  142.  
  143. }
  144.  
  145. }
  146.  
  147. //shuffle
  148.  
  149. if(shuffle){
  150.  
  151. this.shuffleDeck();
  152.  
  153. }
  154.  
  155. }
  156.  
  157. // custom shuffle function--if <list> was used, it has a shuffle method build in
  158.  
  159. public void shuffleDeck(){
  160.  
  161. Random rng = new Random();
  162.  
  163. Cards temp;
  164.  
  165. // swapping
  166.  
  167. int j;
  168.  
  169. for(int i=0; i<this.numOfCardsInDeck;i++){
  170.  
  171. j = rng.nextInt(this.numOfCardsInDeck);
  172.  
  173. temp = this.cardsInDeck[i];
  174.  
  175. this.cardsInDeck[i] = this.cardsInDeck[j];
  176.  
  177. this.cardsInDeck[j] = temp;
  178.  
  179. }
  180.  
  181. }
  182.  
  183. // dealing a card from deck
  184.  
  185. public Cards dealingNextCard(){
  186.  
  187. Cards topCard = this.cardsInDeck[0];
  188.  
  189. // remove this card -- if arraylist was used, remove method is build in
  190.  
  191. for(int c =1; c<this.numOfCardsInDeck;c++){
  192.  
  193. this.cardsInDeck[c-1] = this.cardsInDeck[c];
  194.  
  195. }
  196.  
  197. this.cardsInDeck[this.numOfCardsInDeck - 1] = null;
  198.  
  199. this.numOfCardsInDeck--;
  200.  
  201. return topCard;
  202.  
  203. }
  204.  
  205. public void printDeckCards(int num){
  206.  
  207. for(int c=0; c<num; c++){
  208.  
  209. System.out.printf("% 3d/%d %s\n", c+1, this.numOfCardsInDeck, this.cardsInDeck[c].toString());
  210.  
  211. }
  212.  
  213. System.out.printf("\t\t[%d other]\n", this.numOfCardsInDeck - num);
  214.  
  215. }
  216.  
  217. }
  218.  
  219. //class player, player.java
  220.  
  221. package blackjackgame;
  222.  
  223. public class Players {
  224.  
  225. private String playerName;
  226.  
  227. private Cards[] playerHand = new Cards[10];
  228.  
  229. private int numCardsInHand;
  230.  
  231. public Players(String name){
  232.  
  233. this.playerName = name;
  234.  
  235. this.emptyHand();
  236.  
  237. }
  238.  
  239. public void emptyHand(){
  240.  
  241. for(int hc=0; hc<10;hc++){
  242.  
  243. this.playerHand[hc] = null;
  244.  
  245. }
  246.  
  247. this.numCardsInHand = 0;
  248.  
  249. }
  250.  
  251. public boolean addCardToPlayersHand(Cards card){
  252.  
  253. if(this.numCardsInHand == 10){
  254.  
  255. System.err.printf("%s's hand already has 10 cards; cannot add more cards", this.playerName);
  256.  
  257. System.exit(1);
  258.  
  259. }
  260.  
  261. this.playerHand[this.numCardsInHand] = card;
  262.  
  263. this.numCardsInHand++;
  264.  
  265. return (this.getPlayersHandTotal() <=21);
  266.  
  267. }
  268.  
  269. public int getPlayersHandTotal(){
  270.  
  271. int handTotal = 0;
  272.  
  273. int cardNum;
  274.  
  275. int numAces = 0;
  276.  
  277. //System.out.printf("getPlayersHandTotal :%d\n ", this.numCardsInHand);
  278.  
  279. for(int c =0; c<this.numCardsInHand;c++){
  280.  
  281. cardNum = this.playerHand[c].getCardNumber();
  282.  
  283. //System.out.printf("getPlayersHandTotal: %s\n%d", this.playerHand[c], cardNum);
  284.  
  285. if(cardNum == 1){ // Ace
  286.  
  287. numAces++;
  288.  
  289. handTotal += 11;
  290.  
  291. }
  292.  
  293. else if(cardNum >= 10){
  294.  
  295. handTotal += 10;
  296.  
  297. }
  298.  
  299. else{
  300.  
  301. handTotal += cardNum;
  302.  
  303. }
  304.  
  305. }
  306.  
  307. while(handTotal > 21 && numAces > 0){
  308.  
  309. handTotal -= 10;
  310.  
  311. numAces--;
  312.  
  313. }
  314.  
  315. return handTotal;
  316.  
  317. }
  318.  
  319. public void printCardsInHand(boolean showFirstCard){
  320.  
  321. System.out.printf("\n%s's cards in hand\n\n", this.playerName);
  322.  
  323. for(int c=0; c<this.numCardsInHand;c++){
  324.  
  325. if(!showFirstCard && c==0){
  326.  
  327. System.out.printf("\t[hidden]\n");
  328.  
  329. }
  330.  
  331. else{
  332.  
  333. System.out.printf("\t%s\n\n", this.playerHand[c]);
  334.  
  335. }
  336.  
  337. }
  338.  
  339. }
  340.  
  341. public boolean splitPossible(){
  342.  
  343. if(this.numCardsInHand == 2 && (this.playerHand[0].getCardNumber() == this.playerHand[1].getCardNumber())){
  344.  
  345. return true;
  346.  
  347. }
  348.  
  349. else{
  350.  
  351. return false;
  352.  
  353. }
  354.  
  355. }
  356.  
  357. }
  358.  
  359. // this just a extra suits class with enum to define all 52 card variation, Suits.java
  360.  
  361. package blackjackgame;
  362.  
  363. public enum Suits {
  364.  
  365. Clubs,
  366.  
  367. Diamonds,
  368.  
  369. Hearts,
  370.  
  371. Spades,
  372.  
  373. }
  374.  
  375. // main function , GameMain.java, it has the both dearler and player instances. This is the driver class to play the game
  376.  
  377. package blackjackgame;
  378.  
  379. import java.util.Scanner;
  380.  
  381. import java.util.InputMismatchException;
  382.  
  383. public class GameMain {
  384.  
  385. private Deck newDeck;
  386.  
  387. private String playerName;
  388.  
  389. private float balance;
  390.  
  391. private float bet;
  392.  
  393. private boolean youDone;
  394.  
  395. private boolean dealerDone;
  396.  
  397. private Players dealer;
  398.  
  399. private Players you;
  400.  
  401. private Scanner sc = new Scanner(System.in);
  402.  
  403. private boolean doubleDownAllowed;
  404.  
  405. GameMain(String pName){
  406.  
  407. this.balance = 100;
  408.  
  409. this.newDeck = new Deck(4, true);
  410.  
  411. boolean gameOver = false;
  412.  
  413. this.playerName = pName;
  414.  
  415. System.out.println("######################################################################################");
  416.  
  417. System.out.println(this.playerName+", you have $100 ");
  418.  
  419. System.out.println("######################################################################################");
  420.  
  421. // Players init
  422.  
  423. you = new Players(this.playerName);
  424.  
  425. dealer = new Players("Dealer");
  426.  
  427. // Game Starts here --->
  428.  
  429. while(this.balance > 0 && !gameOver){
  430.  
  431. System.out.println("\n"+this.playerName+", Do you want to DEAL or END the game [D or E]??");
  432.  
  433. String gameInit = sc.next();
  434.  
  435. if(gameInit.compareToIgnoreCase("D") == 0){
  436.  
  437. this.dealTheGame();
  438.  
  439. }
  440.  
  441. else{
  442.  
  443. gameOver = true;
  444.  
  445. }
  446.  
  447. }
  448.  
  449. System.out.println("\n"+this.playerName+", !!!! Game Ended !!!");
  450.  
  451. // To play again
  452.  
  453. System.out.println("\n"+this.playerName+", Do you want to play again [Y or N]");
  454.  
  455. String Y = sc.next();
  456.  
  457. if(Y.compareToIgnoreCase("Y") == 0){
  458.  
  459. new GameMain(this.playerName);
  460.  
  461. }
  462.  
  463. //closing scanner
  464.  
  465. sc.close();
  466.  
  467. }
  468.  
  469. // Deal the game
  470.  
  471. private void dealTheGame(){
  472.  
  473. boolean blackjack = false;
  474.  
  475. this.bet = 0 ;
  476.  
  477. this.doubleDownAllowed = true;
  478.  
  479. System.out.printf("\nBalance:$%.1f\n", this.balance);
  480.  
  481. String msg = "Enter your bet for this game:";
  482.  
  483. while(this.bet<=0){
  484.  
  485. try{
  486.  
  487. System.out.println("\n"+msg);
  488.  
  489. this.bet = sc.nextFloat();
  490.  
  491. }catch(InputMismatchException e){
  492.  
  493. //System.err.println("Caught InputMismatchException: " + e.getMessage());
  494.  
  495. //throw e;
  496.  
  497. sc.nextLine();
  498.  
  499. }finally{
  500.  
  501. msg = "Enter your bet in Integers (natural numbers) please:";
  502.  
  503. }
  504.  
  505. }
  506.  
  507. if((this.bet >= 1) && (this.bet%1 == 0) && (this.balance-this.bet>=0)){
  508.  
  509. this.balance = this.balance - this.bet;
  510.  
  511. // players start with empty hands
  512.  
  513. you.emptyHand();
  514.  
  515. dealer.emptyHand();
  516.  
  517. this.youDone = false;
  518.  
  519. this.dealerDone = false;
  520.  
  521. // Distributing initial cards to players
  522.  
  523. you.addCardToPlayersHand(newDeck.dealingNextCard());
  524.  
  525. dealer.addCardToPlayersHand(newDeck.dealingNextCard());
  526.  
  527. you.addCardToPlayersHand(newDeck.dealingNextCard());
  528.  
  529. dealer.addCardToPlayersHand(newDeck.dealingNextCard());
  530.  
  531. // Cards Dealt
  532.  
  533. System.out.println("\n########## CARDS DEALT ##########\n");
  534.  
  535. dealer.printCardsInHand(false);
  536.  
  537. you.printCardsInHand(true);
  538.  
  539. System.out.printf("Your Score:%d\t", you.getPlayersHandTotal());
  540.  
  541. System.out.printf("Bet:$%.0f\t", this.bet);
  542.  
  543. System.out.printf("Balance:$%.1f\n\n", this.balance);
  544.  
  545. // checking state on initial card -- if BlackJack
  546.  
  547. blackjack = this.checkIfBlackJack();
  548.  
  549. while(!this.youDone || !this.dealerDone){
  550.  
  551. if(!this.youDone){
  552.  
  553. this.yourPlay();
  554.  
  555. }
  556.  
  557. else if(!this.dealerDone){
  558.  
  559. this.dealersPlay();
  560.  
  561. }
  562.  
  563. System.out.println();
  564.  
  565. }
  566.  
  567. if(!blackjack){
  568.  
  569. this.decideWinner();
  570.  
  571. }
  572.  
  573. }
  574.  
  575. else{
  576.  
  577. System.out.println("\nYour bet amount is wrong, it should be a natural number and should not exceed your balance");
  578.  
  579. System.out.printf("Your Balance:$%.1f\n\n", this.balance);
  580.  
  581. }
  582.  
  583. }
  584.  
  585. // Natural 21 check on initial cards
  586.  
  587. private boolean checkIfBlackJack(){
  588.  
  589. boolean blackJack = false;
  590.  
  591. if(you.getPlayersHandTotal() == 21){
  592.  
  593. this.youDone = true;
  594.  
  595. this.dealerDone = true;
  596.  
  597. if(you.getPlayersHandTotal() > dealer.getPlayersHandTotal() || dealer.getPlayersHandTotal() > 21){
  598.  
  599. System.out.println("\t\t\t\t#################################");
  600.  
  601. System.out.println("\t\t\t\t# #");
  602.  
  603. System.out.println("\t\t\t\t# HURRAY!!...BLACKJACK, YOU WON #");
  604.  
  605. System.out.println("\t\t\t\t# #");
  606.  
  607. System.out.println("\t\t\t\t#################################\n");
  608.  
  609. dealer.printCardsInHand(true);
  610.  
  611. System.out.printf("Dealer's Score:%d\n\n", dealer.getPlayersHandTotal());
  612.  
  613. System.out.printf("Your Bet was :$%.0f\t", this.bet);
  614.  
  615. System.out.printf("Your Balance was:$%.1f\n", this.balance);
  616.  
  617. System.out.printf("You win[3:2]:$%.1f\t", (3*this.bet)/2);
  618.  
  619. this.balance = this.balance + (3*this.bet)/2 + this.bet;
  620.  
  621. System.out.printf("Your Current Balance:$%0.1f\n", this.balance);
  622.  
  623. blackJack = true;
  624.  
  625. }
  626.  
  627. else{
  628.  
  629. System.out.println("\tIt could have been a BlackJack for you...\n");
  630.  
  631. dealer.printCardsInHand(true);
  632.  
  633. System.out.printf("Dealer's Score:%d\n\n", dealer.getPlayersHandTotal());
  634.  
  635. blackJack = false;
  636.  
  637. }
  638.  
  639. }
  640.  
  641. else if(dealer.getPlayersHandTotal() == 21){
  642.  
  643. dealer.printCardsInHand(true);
  644.  
  645. System.out.printf("Dealer's Score:%d\n\n", dealer.getPlayersHandTotal());
  646.  
  647. System.out.println("\t\t\t\t#################################");
  648.  
  649. System.out.println("\t\t\t\t# #");
  650.  
  651. System.out.println("\t\t\t\t# DEALER's BLACKJACK, YOU LOST #");
  652.  
  653. System.out.println("\t\t\t\t# #");
  654.  
  655. System.out.println("\t\t\t\t#################################\n");
  656.  
  657. this.dealerDone = true;
  658.  
  659. blackJack = false;
  660.  
  661. }
  662.  
  663. return blackJack;
  664.  
  665. }
  666.  
  667. // Player's Play Turn
  668.  
  669. private void yourPlay(){
  670.  
  671. String answer;
  672.  
  673. /*
  674.  
  675. * flags- Hit, Stand, Double, Split
  676.  
  677. * ---------------------------------
  678.  
  679. */
  680.  
  681. if(this.balance >= this.bet && this.doubleDownAllowed){
  682.  
  683. System.out.print("Hit or Stay or Double Down? [Enter H or S or DD]");
  684.  
  685. }
  686.  
  687. else{
  688.  
  689. this.doubleDownAllowed = false;
  690.  
  691. System.out.print("Hit or Stay? [Enter H or S(or press any letter to Stay)]");
  692.  
  693. }
  694.  
  695. answer = sc.next();
  696.  
  697. System.out.println();
  698.  
  699. if(answer.compareToIgnoreCase("H") == 0){
  700.  
  701. this.hit();
  702.  
  703. this.doubleDownAllowed = false;
  704.  
  705. }
  706.  
  707. else if(answer.compareToIgnoreCase("DD") == 0 && this.doubleDownAllowed){
  708.  
  709. this.doubleDown();
  710.  
  711. }
  712.  
  713. else if(answer.compareToIgnoreCase("SS") == 0){
  714.  
  715. //this.split();
  716.  
  717. this.doubleDownAllowed = false;
  718.  
  719. }
  720.  
  721. else{
  722.  
  723. this.stay();
  724.  
  725. }
  726.  
  727. }
  728.  
  729. // Player's Hit
  730.  
  731. private void hit(){
  732.  
  733. System.out.println("\tYou Choose to Hit.\n");
  734.  
  735. youDone = !you.addCardToPlayersHand(newDeck.dealingNextCard());
  736.  
  737. you.printCardsInHand(true);
  738.  
  739. System.out.printf("Your Score:%d\t", you.getPlayersHandTotal());
  740.  
  741. System.out.printf("Bet:$%.0f\t", this.bet);
  742.  
  743. System.out.printf("Balance:$%.1f\n\n", this.balance);
  744.  
  745. if(you.getPlayersHandTotal()>21){
  746.  
  747. System.out.println("\t\t\t\t##############");
  748.  
  749. System.out.println("\t\t\t\t# #");
  750.  
  751. System.out.println("\t\t\t\t# YOU BUSTED #");
  752.  
  753. System.out.println("\t\t\t\t# #");
  754.  
  755. System.out.println("\t\t\t\t##############\n");
  756.  
  757. dealer.printCardsInHand(true);
  758.  
  759. System.out.printf("Dealer's Score:%d\n\n", dealer.getPlayersHandTotal());
  760.  
  761. youDone = true;
  762.  
  763. dealerDone = true;
  764.  
  765. }
  766.  
  767. }
  768.  
  769. // Player's Stay
  770.  
  771. private void stay(){
  772.  
  773. System.out.println("\tYou Choose to Stay, Dealer's turn \n");
  774.  
  775. youDone = true;
  776.  
  777. }
  778.  
  779. // Player's Double Down
  780.  
  781. private void doubleDown(){
  782.  
  783. System.out.println("\tYou Choose to Double Down.\n");
  784.  
  785. youDone = you.addCardToPlayersHand(newDeck.dealingNextCard());
  786.  
  787. this.balance = this.balance - this.bet;
  788.  
  789. this.bet = 2*this.bet;
  790.  
  791. youDone = true;
  792.  
  793. you.printCardsInHand(true);
  794.  
  795. System.out.printf("Your Score:%d\t", you.getPlayersHandTotal());
  796.  
  797. System.out.printf("Bet:$%.0f\t", this.bet);
  798.  
  799. System.out.printf("Balance:$%.1f\n\n", this.balance);
  800.  
  801. if(you.getPlayersHandTotal()>21){
  802.  
  803. System.out.println("\t\t\t\t##############");
  804.  
  805. System.out.println("\t\t\t\t# #");
  806.  
  807. System.out.println("\t\t\t\t# YOU BUSTED #");
  808.  
  809. System.out.println("\t\t\t\t# #");
  810.  
  811. System.out.println("\t\t\t\t##############\n");
  812.  
  813. dealer.printCardsInHand(true);
  814.  
  815. System.out.printf("Dealer's Score:%d\n\n", dealer.getPlayersHandTotal());
  816.  
  817. youDone = true;
  818.  
  819. dealerDone = true;
  820.  
  821. }
  822.  
  823. System.out.println("Now , Dealer's turn \n");
  824.  
  825. }
  826.  
  827. // Dealer's Play Turn
  828.  
  829. private void dealersPlay(){
  830.  
  831. if(dealer.getPlayersHandTotal() < 17){
  832.  
  833. dealer.printCardsInHand(true);
  834.  
  835. System.out.printf("Dealer's Score:%d\n\n", dealer.getPlayersHandTotal());
  836.  
  837. System.out.println("\tDealer Hits \n");
  838.  
  839. dealerDone = !dealer.addCardToPlayersHand(newDeck.dealingNextCard());
  840.  
  841. if(dealer.getPlayersHandTotal()>21){
  842.  
  843. dealer.printCardsInHand(true);
  844.  
  845. System.out.printf("Dealer's Score:%d\n\n", dealer.getPlayersHandTotal());
  846.  
  847. System.out.println("\t\t\t\t#################");
  848.  
  849. System.out.println("\t\t\t\t# #");
  850.  
  851. System.out.println("\t\t\t\t# DEALER BUSTED #");
  852.  
  853. System.out.println("\t\t\t\t# #");
  854.  
  855. System.out.println("\t\t\t\t#################\n");
  856.  
  857. dealerDone = true;
  858.  
  859. }
  860.  
  861. }
  862.  
  863. else{
  864.  
  865. dealer.printCardsInHand(true);
  866.  
  867. System.out.printf("Dealer's Score:%d\n\n", dealer.getPlayersHandTotal());
  868.  
  869. System.out.println("\tDealer Stays \n");
  870.  
  871. dealerDone = true;
  872.  
  873. }
  874.  
  875. }
  876.  
  877. // Deciding a Winner
  878.  
  879. private void decideWinner(){
  880.  
  881. int youSum = you.getPlayersHandTotal();
  882.  
  883. int dealerSum = dealer.getPlayersHandTotal();
  884.  
  885. if(youSum>dealerSum && youSum<=21 || dealerSum >21){
  886.  
  887. System.out.println("\t\t\t\t############");
  888.  
  889. System.out.println("\t\t\t\t# #");
  890.  
  891. System.out.println("\t\t\t\t# YOU WON #");
  892.  
  893. System.out.println("\t\t\t\t# #");
  894.  
  895. System.out.println("\t\t\t\t############\n");
  896.  
  897. System.out.printf("Your Bet was :$%.0f\t", this.bet);
  898.  
  899. System.out.printf("Your Balance was:$%.1f\n", this.balance);
  900.  
  901. System.out.printf("You win[1:1] :$%.0f\t", this.bet);
  902.  
  903. this.balance = this.balance + this.bet + this.bet;
  904.  
  905. System.out.printf("Your Current Balance:$%.1f\n", balance);
  906.  
  907. }
  908.  
  909. else if(youSum == dealerSum){
  910.  
  911. System.out.println("\t\t\t\t############");
  912.  
  913. System.out.println("\t\t\t\t# #");
  914.  
  915. System.out.println("\t\t\t\t# PUSH #");
  916.  
  917. System.out.println("\t\t\t\t# #");
  918.  
  919. System.out.println("\t\t\t\t############\n");
  920.  
  921. this.balance = this.balance + this.bet;
  922.  
  923. System.out.printf("Your Current Balance:$%.1f\n", this.balance);
  924.  
  925. }
  926.  
  927. else{
  928.  
  929. System.out.println("\t\t\t\t############");
  930.  
  931. System.out.println("\t\t\t\t# #");
  932.  
  933. System.out.println("\t\t\t\t# YOU LOST #");
  934.  
  935. System.out.println("\t\t\t\t# #");
  936.  
  937. System.out.println("\t\t\t\t############\n");
  938.  
  939. System.out.printf("You lose[1:1]: $%.0f!!\n", this.bet);
  940.  
  941. System.out.printf("Your Current Balance:$%.1f\n", this.balance);
  942.  
  943. }
  944.  
  945. }
  946.  
  947. public static void main(String[] args) {
  948.  
  949. Scanner scanner = new Scanner(System.in);
  950.  
  951. String playerName;
  952.  
  953. System.out.println("\n\t\t\t\t#######################################");
  954.  
  955. System.out.println("\t\t\t\t# #");
  956.  
  957. System.out.println("\t\t\t\t# BLACKJACK 0.1 #");
  958.  
  959. System.out.println("\t\t\t\t# Insight Fellowship Coding Challenge #");
  960.  
  961. System.out.println("\t\t\t\t# #");
  962.  
  963. System.out.println("\t\t\t\t#######################################\n");
  964.  
  965. System.out.println("Enter Your Name:\n");
  966.  
  967. playerName = scanner.nextLine();
  968.  
  969. new GameMain(playerName);
  970.  
  971. scanner.close();
  972.  
  973. }
  974.  
  975. }
  976.  
  977. The prompt are taken as string instead of integer in Y/N format. all classes and methods are commented properly.
Advertisement
Add Comment
Please, Sign In to add comment