My run time error occurs when my program ask for input on to whether"hit or stay"
import java.util.Scanner;
import java.io.*;
public class MainDisplay {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
//Introductions
int bet=0;
String response;
boolean play=true;
System.out.println("Hello and Welcome to BlackJack 1.0");
System.out.println("This was created by Ethan Keiser");
System.out.println("You start out with $1,000 Good Luck!");
System.out.println("How much would you like to bet?");
bet=scan.nextInt();
// Creates a new player and dealer.
Game p=new Player();
Game d=new Dealer();
//while(play){
// Shuffle and deals cards
p.showCards();
d.showCards();
// response
System.out.println("\nWould you like to hit or stay? ");
System.out.println("(type \"h\" for hit and \"s\" for stay.)");
response =scan.nextLine();
if(response.equals("h"))
{
p.ifHit();
if(p.isBusted()){
p.lose(bet);
System.out.println("Play again ?? y for yes n for no");
response =scan.nextLine();
if(response.equals("y"))
play=true;
else if(response =="n")
play=false;
}
else if(!p.isBusted()&&d.isBusted())
{
p.win(bet);
response =scan.nextLine();
if(response.equals("y"))
play=true;
else if(response =="n")
play=false;
}
}
else
p.isWinner(d);
{
}
}
}
any ideas?here are the other three classes
public class Dealer extends Game {
private int dcard1,dcard2,dcard3,total;
public Dealer(){
dcard1=0;
dcard2=0;
dcard3=0;
}
public void shuffleCards() {
dcard1=shuffle();
dcard2=shuffle();
dcard3=shuffle();
}
public void showCards(){
shuffleCards();
total=(dcard1+dcard2);
System.out.print(toString());
}
public void addCard(int a){
total+=a;
}
int getCard1() {
return dcard1;
}
int getCard2() {
// TODO Auto-generated method stub
return dcard2;
}
int getCard3() {
// TODO Auto-generated method stub
return dcard3;
}
public int getTotal(){
return total;
}
public String toString()
{
String str="\nDealers shows : "+dcard1;
return str;
}
@Override
void shuffleCard1() {
dcard1=shuffle();
}
@Override
void shuffleCard2() {
dcard2=shuffle();
}
@Override
void shuffleCard3() {
dcard3=shuffle();
}
@Override
void lose(int m) {
}
@Override
void win(int m) {
}
}
public abstract class Game {
abstract void showCards();
abstract void shuffleCards();
abstract int getCard1();
abstract int getCard2();
abstract int getCard3();
abstract void shuffleCard1();
abstract void shuffleCard2();
abstract void shuffleCard3();
abstract void addCard(int m);
abstract int getTotal();
abstract void lose(int m);
abstract void win(int m);
public void ifHit()
{
shuffleCard3();
addCard(getCard3());
}
public int shuffle(){
int a=(int)((Math.random()*5)+1);
return a;
}
public boolean isBusted(){
if (this.getTotal()>21)
return true;
else
return false;
}
public boolean isWinner(Game d){
if( this.getTotal()>= d.getTotal());
return true;
}
}
public class Player extends Game{
private int pcard1,pcard2,pcard3,amount,total;
public Player(){
pcard1=0;
pcard2=0;
pcard3=0;
amount=1000;
}
public void shuffleCards() {
pcard1=shuffle();
pcard2=shuffle();
pcard3=shuffle();
}
public void showCards(){
shuffleCards();
total=(pcard1+pcard2);
System.out.print(toString());
}
public void shuffleCard1(){
pcard1=shuffle();
}
public void shuffleCard2(){
pcard2=shuffle();
}
public void shuffleCard3(){
pcard3=shuffle();
}
public void addCard(int a){
total+=a;
}
public int getTotal(){
return total;
}
public int getCard1(){
return pcard1;
}
public int getCard2(){
return pcard2;
}
public int getCard3(){
return pcard3;
}
public void addAmount(int m){
amount+=m;
}
public void subtractAmount(int m){
amount-=m;
}
public int getAmount(){
return amount;
}
public void win(int bet){
System.out.println("Congradulations you won "+bet);
addAmount(bet);
}
public void lose (int bet)
{
System.out.println("Sorry you lost "+bet);
subtractAmount(bet);
}
public String toString()
{
String str="\nCard 1: "+pcard1+" "+"Card 2: "+pcard2;
str+=" \nTotal: "+(pcard1+pcard2);
return str;
}
} I am sure the error is basic but any idea's would be greatly appreciated. Its not finish of course.


Sign In
Create Account

Back to top









