this is my code - i have three classes and i will post all since i have no idea what i'm doing apparently
public class OneTwoTest
{
public static void main(String[] args)
{
System.out.println("Welcome to One-Two Match!");
Game g = new Game();
g.play();
System.out.println("Thank you for playing.");
} // end main
} //end class
import java.util.Scanner;
public class Game
{
public Player p1; // human or computer player
public Player p2; // computer player
int again;
int sum;
int a;
int b;
public Game()
{
p1 = new Player(a);
p2 = new Player(b);
}
public void play()
{
sum = p1.declare() + p2.declare();
if(sum%2==0)
{
p2.deposit(sum);
p1.withdraw(sum);
}
else
{
p1.withdraw(sum);
p2.deposit(sum);
}
if(p1.score() > p2.score())
System.out.println("Congratulations. Player 1 wins!");
else
System.out.println("Player 1 loses!");
}
} // end of class
import java.util.Scanner;
public class Player
{
private boolean isHuman;
private int score=0;
private Scanner input;
public Player(int human)
{
System.out.println("If you would like to play, press 1. Otherwise, press 0 to have two computers play against each other.");
human = input.nextInt();
if (human>0)
isHuman=true;
else
isHuman=false;
}
public int declare()
{
int theThrow;
if(isHuman=true)
{
input = new Scanner(System.in);
System.out.println("What would you like to throw? Enter either 1 or 2.");
theThrow = input.nextInt();
System.out.println("You threw a " + theThrow);
}
else
{
double t;
t = (double) Math.random();
theThrow = (int) (t+1.5);
System.out.println("The computer threw a " + theThrow);
}
return theThrow;
}
public void deposit(int amount)
{
score = score + amount;
}
public void withdraw(int amount)
{
score = score - amount;
}
public int score()
{
return score;
}
}
I get the following message
Welcome to One-Two Match!
If you would like to play, press 1. Otherwise, press 0 to have two computers play against each other.
Exception in thread "main" java.lang.NullPointerException
at Player.<init>(Player.java:14)
at Game.<init>(Game.java:16)
at OneTwoTest.main(OneTwoTest.java:9)
Where is my mistake? I keep looking over it and can't find anything wrong. Please be explicit! Thank you