Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Using the Coin Class The Coin class from Listing 4.2 in the text is in the file Coin.java. Copy it to your directory, then

Java

image text in transcribed

image text in transcribed

Using the Coin Class The Coin class from Listing 4.2 in the text is in the file Coin.java. Copy it to your directory, then write a program to find the length of the longest run of heads in 100 flips of the coin. A skeleton of the program is in the file Runs.java. To use the Coin class you need to do the following in the program: 1. Create a coin object. 2. Inside the loop, you should use the flip method to flip the coin, the toString method (used implicitly) to print the results of the flip, and the getFace method to see if the result was HEADS. Keeping track of the current run length (the number of times in a row that the coin was HEADS) and the maximum run length is an exercise in loop techniques! 3. Print the result after the l / Coin.java Author: Lewis and Loftus Represents a coin with two sides that can be flipped public class Coin public final int HEADS0 public final int TAILS1; private int face; /1 Sets up the coin by flipping it initially public Coin () flip) // Flips the coin by randomly choosing a face. public void flip() face - (int) (Math.random() 2) / Returns true if the current face of the coin is heads. public boolean isHeads () return (faceHEADS) // Returns the current face of the coin as a string public String toString () String faceName; if (faceHEADS) faceName - "Heads

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

Step: 3

blur-text-image

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

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions