import java.util.*;
public class Pig{
public static void main (String [] args){
int player1 = 0;
int player2 = 0;
String s = "";
String b = prompt(s);
if (b.charAt(0) =='y'){
player1();
player2();
} else{
System.out.println("Too bad maybe next time!!");
}
}
//Initial Prompt
public static String prompt (String s){
System.out.println ("Welcome to the game of \"pig\".");
System.out.println ("This is a two-player game.");
System.out.println ("The first player rolls a 6-sided die.");
System.out.println ("The player can roll as many times as she/he");
System.out.println ("likes until she/he wishes to stop or gets a 1.");
System.out.println ("If the first player chooses to stop, she/he");
System.out.println ("gets the sum of all her/his rolls added to");
System.out.println ("her/his score. If the first player stops becuase");
System.out.println ("she/he has rolled a one, she/he gets no points");
System.out.println ("for that turn. The first player to reach 100");
System.out.println ("points wins the game.");
System.out.print ("Do you want to play(y/n)? ");
String c = scanner();
return c;
}
// Turn for first player
public static void player1 (){
System.out.println ("PLAYER 1 ************************************ rolling...");
do{
int i = random();
System.out.println("You rolled a "+i);
System.out.print("Do you want to rolla gain? ");
String c = scanner();
String d = c.toLowerCase();
} while (d.charAt(0) == 'y');
System.out.println("A wise choice");
}
//Turn for second player
public static void player2 (){
System.out.println ("PLAYER 2 ************************************ rolling...");
do{
int i = random();
System.out.println("You rolled a "+i);
System.out.print("Do you want to rolla gain? ");
String c = scanner();
String d = c.toLowerCase();
} while (d.charAt(0) == 'y');
System.out.println("A wise choice");
}
//Generates numbers
public static int random (){
Random rand = new Random ();
int random = rand.nextInt (6)+1;
return random;
}
//Scanner input
public static String scanner (){
Scanner sc = new Scanner (System.in);
String yn = sc.next();
String s = yn.toLowerCase();
return s;
}
}
--- Update ---
these are the error messages i received:
ivans-mbpocuments IvanBaird$ javac Pig.java
Pig.java:43: cannot find symbol
symbol : variable c
location: class Pig
} while (c.charAt(0) == 'y');
^
Pig.java:56: cannot find symbol
symbol : variable d
location: class Pig
} while (d.charAt(0) == 'y');
^
2 errors