Results 1 to 2 of 2

Thread: Pontoon Error

  1. #1
    Dave013 is offline Member
    Join Date
    Oct 2011
    Location
    Shrewsbury, Shropshire
    Posts
    6
    Rep Power
    0

    Default Pontoon Error

    I have got this code but when I run it I it should be that the it goes bust after 21. It does not do this any ideas.

    import java.util.Scanner;

    public class Pontoon{

    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int playerScore = 0, computerScore = 0;
    String newCard = "";
    playerScore += dealCard();
    computerScore += dealCard();
    playerScore += dealCard();
    computerScore += dealCard();

    System.out.printf("Your score is %d would you like another card ? y/n ", playerScore);
    newCard = input.nextLine();
    if(newCard.equalsIgnoreCase("Y")) {
    while (newCard.equalsIgnoreCase("Y")) {
    playerScore += dealCard();
    System.out.printf("Your score is %d would you like another card ? y/n ", playerScore);
    newCard = input.nextLine();
    }
    }
    while(computerScore < 15){
    computerScore += dealCard();
    }
    checkWin(playerScore, computerScore);
    }
    public static int dealCard(){
    int value = (int) (Math.random() * 13) + 1;
    int score = 0;
    if(value == 1) {
    System.out.println("Ace!");
    score = 11;
    }else if (value == 13) {
    System.out.println("King!");
    score = 10;
    }else if (value == 12) {
    System.out.println("Queen!");
    score = 10;
    } else if (value == 11) {
    System.out.println("Jack!");
    score = 10;
    } else {
    score = value;
    }

    return score;
    }

    public static void checkWin(int Player, int Computer) {
    int player = Player;
    int computer = Computer;

    if (player > 21) {
    System.out.println("Player Bust");
    } else if (computer > 21) {
    System.out.println("Computer Bust");
    } else {
    if (player > computer) {
    System.out.println("Player Wins!");
    } else {
    System.out.println("Computer Wins!");
    }
    }
    }

    private Pontoon() {
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. java out of memory error-heap space error
    By elsanthosh in forum NetBeans
    Replies: 4
    Last Post: 06-15-2010, 09:31 AM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 04:38 PM
  5. Replies: 3
    Last Post: 01-23-2009, 08:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •