I have narrowed the problem down to my method and I realize it is not truly random but this is the method we were told to use as we have just started programming a little while ago.
Any help is appreciated!
Method first:
import java.util.Scanner;
import java.util.Random;
public class Methods
public static int Flip ( int toss ) //coin flip method
{
Random randomNumbers = new Random();
toss = 1 + randomNumbers.nextInt(2);
return toss;
}
Program Code:
import java.util.Scanner;
public class CoinTossing
{
public static void main(String[]args)
{
Scanner input = new Scanner(System.in);
//variables
int selection;
int flip;
int heads = 0;
int tails = 0;
//menu
System.out.print("Press 1 for a coin flip\nPress anything else to exit\n");
selection = input.nextInt();
while (selection == 1) //loop
{
//Method import
flip = Methods.Flip( selection ); //begins flip
if (flip == 1) //returns heads
System.out.println("you have returned a heads");
heads++;
if (flip != 1) //returns tails
System.out.println("you have returned a tails");
tails++;
System.out.print("Press 1 for a coin flip\nPress anything else to exit\n");
selection = input.nextInt();
}
//Results
System.out.printf("You flipped %d for heads, and %d for tails", heads, tails);
}
}
It should be noted that the problem I experienced has been narrowed to the method as I don't receive any problems with the actual code, but if you feel something else should be changed I would be open to it, after all I'm still learning.
Cheers!

New Topic/Question
Reply



MultiQuote



|