I'm having trouble figuring out what I should be doing with this, the goal of this is to transfer the value that I've inputted from the console in one of the methods and transfer it to another method. My professor said that we cannot change the method headers in any way and I am just lost at how I'm supposed to do this.
Specifically speaking, this is a coin tossing game that I'm making and I have a method for determining the amount of times the user wants to flip the coin(determineNumberOfTosses()). Then using another method(playCoinToss()), I have to generate random integers between 1 and 0 and count how many are 'heads' and how many are 'tails'. The problem is I can't specify the value for the count in the 'for' loop because of the value only existing where I inputted and where I returned it to.
I cannot change the main method as specified by my professor. Thank you for any help given.
I'm sorry in advance for the giant block of code.
public static void playGame()
{
int numTosses; // number of coin tosses
numTosses = 0;
numTosses = determineNumberOfTosses();
playCoinToss();
} // end playGame
//
// playCoinToss
//
// the purpose of this method is to play the coin toss
// portion of the random number game
//
// Input: none
// Return: none
//
public static void playCoinToss()
{
int coinSideHeads; // heads side of the coin counter
int coinSideTails; // tails side of the coin counter
int cntr; // counter for the loop
final int HEADS = 0; // heads side of the coin
final int TAILS = 1; // tails side of the coin
int rNum; // random number generated between 1 and 0
coinSideHeads = 0;
coinSideTails = 0;
cntr = 0;
for(cntr = 0; cntr < ; ++cntr)
{
rNum = (int)(Math.random() * ((TAILS - HEADS) + 1));
if(rNum == 0)
{
coinSideHeads = coinSideHeads + 1;
}
else
{
coinSideTails = coinSideTails + 1;
} // end if
} // end loop
} // end playCoinToss
//
// determineNumberOfTosses
//
// the purpose of this method is to determine a valid number
// of coin tosses to complete
//
// Input: none
// Return: numTosses the valid number of tosses to complete
//
public static int determineNumberOfTosses()
{
Scanner input = new Scanner(System.in); // open input stream
String cleanUpStr; // clean keyboard buffer
int numTosses; // number of tosses
numTosses = 0;
System.out.println("How many coin tosses would you like?");
numTosses = input.nextInt();
cleanUpStr = input.nextLine();
return numTosses;
} // end determineNumbverOfTosses
Comments
Post a Comment