My instructor has requested a change to my Coin Tossing program that I have written but I need to know what to change, need help.
This is what the instructor requested:
As written in the textbook, the user is able to choose to toss the coin repeatedly, and the program will report the result of tossing the coin each additional time (i.e., the results of the tosses should be cumulative). Instead, write the CoinTossing class so that rather than just doing one toss at a time, the user may input a integral value saying how many additional tosses are to be performed each time. The program will terminate if the user enters "0", indicating that the user wishes no more tosses of the coin. After each entry from the user, output the total count (from the start of the execution of the program) of each of the possible outcomes, so that it may be determined whether the simulated coin is "fair".
and here is my code so far:
package tosscoin;
import java.util.Random;
import java.io.DataInputStream;
import java.io.IOException;
/**
*
* @author David Reeves
*/
public class tossCoin {
public int num_heads =0,num_tails =0;
public enum coin {Head,Tail};
private final Random rm = new Random();
public coin flip()
{
coin c;
int i = rm.nextInt(2);
if(i==0)
{
c = coin.Head;
num_heads++;
}
else
{
c = coin.Tail;
num_tails++;
}
return c;
}
public static void main(String[] args) {
// TODO code application logic here
DataInputStream din = new DataInputStream(System.in);
tossCoin ts = new tossCoin();
int choice =0, i=0;
System.out.println("Make a choicenPress 1 to tossnPress 2 to exit ");
while(true)
{
System.out.print("Choice:");
try{
choice = Integer.parseInt(din.readLine());
}
catch(IOException | NumberFormatException E)
{
System.out.println("Invalid choice");
}
switch(choice)
{
case 1: ts.flip();
System.out.println("Heads: "+ts.num_heads +" Tails: "+ ts.num_tails );
break;
case 2: return;
default: System.out.println("Invalid choice. Try again");
}
}
}