Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help understanding this question from CodeStepByStep in Java, any help is appreciated! Write a method named coinFlip that accepts as its parameter a string

Need help understanding this question from CodeStepByStep in Java, any help is appreciated!

Write a method named coinFlip that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of whitespace-separated tokens. Assume that the input file data represents results of sets of coin flips. A coin flip is either the letter H or T, or the word Heads or Tails, in either upper or lower case, separated by at least one space. You should read the sequence of coin flips and output to the console the number of heads and the percentage of heads in that line, rounded to the nearest whole number. If this percentage is 50% or greater, you should print a "You win!" message; otherwise, print "You lose!". For example, consider the following input file:

H T H H T Tails taIlS tAILs TailS heads HEAds hEadS 

For the input above, your method should produce the following output:

6 heads (50%) You win! 

The format of your output must exactly match that shown above. You may assume that the file contains at least 1 token of input, and that no tokens other than heads/tails or H/T will be in the lines. You may assume that the input file exists and is readable.

Constraints: Your solution should read the file only once, not make multiple passes over the file data.

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

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions