Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

s printDuplicates Main Page Problems Solve a Problem Show Header O BJP3 Exercise 6.15: coinFlip processing Scanner Whitaker Brand (on 2013/04/01) Favorite Language/Type: Author: Java

image text in transcribed

s printDuplicates Main Page Problems Solve a Problem Show Header O BJP3 Exercise 6.15: coinFlip processing Scanner Whitaker Brand (on 2013/04/01) Favorite Language/Type: Author: Java file Write a method named coinFlip that accepts as its parameter a Scanner for an input file. Assume that the input file data represents results of sets of coin flips that are either heads (H) or tails (T) in either upper or lower case, separated by at least one space. Your method should consider each line to be a separate set of coin flips and should output to the console the number of heads and the percentage of heads in that line, rounded to the nearest tenth. If this percentage is more than 50%, you should print a "You win" message. For example, consider the following input file HTH H T For the input above, your method should produce the following output 3 heads (60.0%) You win! 2 heads (33.3%) 1 heads (100.0%) You win! The format of your output must exactly match that shown above. You may assume that the Scanner contains at least 1 line of input that each line contains at least one token, and that no tokens other than h, H, t, or T will be in the lines Type your solution here 2 4

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

More Books

Students also viewed these Databases questions