A change to my coin tossing program

Assignment Help Basic Computer Science
Reference no: EM13673936

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");

}

}
}

Reference no: EM13673936

Questions Cloud

The number of completed entries made per hour : The number of completed entries made per hour
The population proportion of customers under age : The population proportion of customers under age 21 is 0.68.
Describes the theory the researchers explore : Describes the theory the researchers explore
An application that stores at least four different courses : Write an application that stores at least four different course names
A change to my coin tossing program : A change to my Coin Tossing program
Describe the main elements of data breach notification : From the e-Activity, describe the main elements of data breach notification laws. Discuss the importance of breach notification for credit card information, as it relates to PCI-DSS.
How is data reported by exif viewer : How is data reported by EXIF Viewer
Show using a state diagram the maca protocol : Show using a state diagram the MACA Protocol
A word document containing all of the identified methods : A word document containing all of the identified methods for the "Zoo Organizer"

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd