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

  True and false

A.  (True | False) In the MSP430's active mode, the MCLK and SMCLK clocks are up and running and ACLK is not running (it is turned off).

  The function return the value of the ticket price

The function return the value of the ticket price time the discount percentage.

  What would you recommend to meet your company needs

Your company wants to implement a strategy for backing up network data. It wants a strategy that allows it to back up changed files on a daily basis and recover lost files quickly in the event of disk failure. What would you recommend to meet your..

  A message stating the purpose of the organization

A message stating the purpose of the organization.

  Validate the information

When all the information is valid, a confirmation screen is displayed. The operator visually confirms that the data are correct and either accepts the transaction or cancels it.

  Determining smallest-last vertex ordering

Determine a smallest-last vertex ordering and plot degree when deleted diagram for given random geometric graphs.

  Optimal substructure of matrix-chain multiplication

Matrices so as to maximize, rather than minimize, number of scalar multiplications. Does this problem show  optimal substructure?

  Project 2 this assignment consists of two 2 sections a

this assignment consists of two 2 sections a business requirements document and a gantt chart or project plan. you must

  Create directories in home directory begin-mac-mac directory

Create following directories in your home directory cp_even, cp_mid,cp_iso,cp,thousand,cp_even. Examine files in the /usr/share/tcl8.3/encoding directory copy all files which begin with mac into mac directory.

  Modify the test scores program from the above debug

Also print a report of the each student's test grades, average and final grade as a table, and then print the averages of each Test and overall Test Average, as well as highest Test Grade of all Tests and the student with the highest class grade.

  Main attributes of product in plug-ins change process

What are some main attributes of product and how may it help operations of organization? How do third-party plug-ins change process of diagnosing and troubleshooting errors in application?

  Explain hardware to gather the essential information

Write down a 2-3 page paper explaining the hardware and software utilized to support personal, workgroup, and enterprise computing in the present organization.

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