Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I need some help with this project. The world depends on its successful compilation. /* CoinTester.java - tests the Coin class by constructing variables

Hi, I need some help with this project. The world depends on its successful compilation.

/*

CoinTester.java - tests the Coin class by

constructing variables and calling it's methods

*/

// VERY IMPORTANT THAT THE TWO COIN's GENERATORS ARE SEEDED WITH TWO DIFFERNT NUMBERS.

// OTHERWISE BOTH COINS WILL ROLL IDENTICAL SEQUENCES.

// WE NEED EACH COIN TO BEHAVE DIFFERENTLY FROM THE OTHER BUT REPEAT THEIR SEQUENCE EVERY RUN.

// (THIS WAY I CAN SCRIPT GRADE THE OUTPUT.)

public class CoinTester

{

public static void main( String args[] )

{

Coin coin1 = new Coin(17); // EACH COIN IS SEEDED WITH A DIFFERENT SEED

Coin coin2 = new Coin(13); // THIS GUARNATEES THEY DON'T ROLL IDENTICAL SEQUENCES

// FLIP COIN1, PRINT RESULTS

import.java.util.Random> public class coin

private int numHeads, numTail;

public coin(int seed)

{

r = new Random (Seed)

numHeads=0;

numTails=0;

}

Coin Coin1 = new Coin (B);

string flip()

{

final int TAILS = 0;

final HEADS = 1 ;

int Side = r.nessatInt(2);

//Side in either 0 or 1

if (Side == HEADS)

System.out.println(Coin1.Rlio()+ " ");

output of flip is 'H' or 'T'

}

System.out.println(" Flipping Coin1 20 times.");

for (int i=0 ; i<20 ; ++i)

System.out.print( coin1.flip() + " " ); // Equal chance of head or tail

System.out.println();

System.out.println("heads=" + coin1.getNumHeads() +

", tails=" + coin1.getNumTails() );

coin1.reset(); // sets numHeads and numTails back to zero;

// FLIP COIN2, PRINT RESULTS

Coin Coin2 = new Coin (B);

string flip()

{

final int TAILS = 0;

final HEADS = 1 ;

int Side = r.nessatInt(2);

//Side in either 0 or 1

if (Side == HEADS)

System.out.println(Coin2.Rlio()+ " ");

output of flip is 'H' or 'T'

}

System.out.println(" Flipping Coin2 10 times.");

for (int i=0 ; i<10 ; ++i)

System.out.print( coin2.flip() + " " ); // Equal chance of head or tail

System.out.println();

System.out.println("heads=" + coin2.getNumHeads() +

", tails=" + coin2.getNumTails() );

coin2.reset(); // sets numHeads and numTails back to zero;

// FLIP COIN2 AGAIN, PRINT RESULTS

Coin Coin2 = new Coin (B);

string flip()

{

final int TAILS = 0;

final HEADS = 1 ;

int Side = r.nessatInt(2);

//Side in either 0 or 1

if (Side == HEADS)

System.out.println(Coin2.Rlio()+ " ");

output of flip is 'H' or 'T'

}

System.out.println(" Flipping Coin1 again 35 times.");

for (int i=0 ; i<35 ; ++i)

System.out.print( coin1.flip() + " " ); // Equal chance of head or tail

System.out.println();

System.out.println("heads=" + coin1.getNumHeads() +

", tails=" + coin1.getNumTails() );

coin1.reset(); // sets numHeads and numTails back to zero;

}// END main

}//EOF

Coin.java class file

/*

Coin.java

*/

import java.util.Random;

public class Coin

{

private Random r; // DO NOT INITIALIZE UP HERE

private int numHeads,numTails; // DO NOT INITIALIZE UP HERE

public Coin( int seed ) // SEED COMES IN FROM MAIN

{

r = new Random( seed ); // INITIALIZE IN CONSTRUCTOR

public static void main(String[] args)

{

int seed = number of heads or number of tails

for (int = heads; int = tails; int++)

{

System.out.println("the number tail" + int tails +

"the number of heads" + int heads);

}

}

}

String flip()

{

final int TAILS=0;

final int HEADS=1;

int side = r.nextInt(2); // produces 0 or 1

if (side==HEADS)

{

++numHeads;

return "H";

}

++numTails;

return "T";

}

public int getNumHeads()

{

return numHeads;

}

public int getNumTails()

{

return numTails;

}

public void reset() // sets num heads and tails back to 0

{

numHeads=numTails=0; // YEAH, YOU CAN CHAIN AN ASSIGNMENT LIKE THIS

}

} //EOF

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

=+Identify trends in the social media industry

Answered: 1 week ago

Question

DEFINE HRIS and describe its main components.

Answered: 1 week ago

Question

Introduce and define metals and nonmetals and explain with examples

Answered: 1 week ago

Question

What is IUPAC system? Name organic compounds using IUPAC system.

Answered: 1 week ago

Question

What happens when carbonate and hydrogen react with carbonate?

Answered: 1 week ago

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago