Results 1 to 2 of 2
Thread: Pontoon Error
- 11-08-2011, 03:23 PM #1
Member
- Join Date
- Oct 2011
- Location
- Shrewsbury, Shropshire
- Posts
- 6
- Rep Power
- 0
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() {
}
}
-
Re: Pontoon Error
Use a debugger or println statements to see why your program is behaving the way it's behaving.
Similar Threads
-
java out of memory error-heap space error
By elsanthosh in forum NetBeansReplies: 4Last Post: 06-15-2010, 09:31 AM -
> Operator cannot be applied error and return incompatible types error
By corney_16 in forum New To JavaReplies: 1Last Post: 03-10-2010, 01:53 PM -
Thread: Error 500--Internal Server Error java.lang.NullPointerException
By jackdear44 in forum New To JavaReplies: 1Last Post: 12-05-2009, 07:28 AM -
java.lang.Error: Error opening DSound for capture
By NARs in forum NetworkingReplies: 1Last Post: 10-26-2009, 04:38 PM -
Diference Between compiler error Garbage collection and Runtime Error?
By makpandian in forum New To JavaReplies: 3Last Post: 01-23-2009, 08:53 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks