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!

Answers

Answer 1

Answer:

Here is the JAVA program:

import java.io.*;

import java.util.*;

public class Main {

public static void main(String[] args) throws FileNotFoundException{ //the start of main() function body, it throws an exception that indicates a failed  attempt to open the file

Scanner input = new Scanner(new File("file.txt")); //creates a Scanner object and a File object to open and scan through the file.txt    

coinFlip(input);    } //calls coinFlip method

public static void coinFlip(Scanner input) { //coinFlip method that accepts as its parameter a string input holding a file name

while(input.hasNextLine()) { //iterates through the input file checking if there is another line in the input file

Scanner scan = new Scanner(input.nextLine()); //creates a Scanner object

int head = 0; // stores count of number of heads

int count = 0; //stores count of  total number of tokens

while(scan.hasNext()) { //iterates through the sequence checking if there is another sequence in the input file

String token= scan.next(); // checks and returns the next token

if (token.equalsIgnoreCase("H")||token.equalsIgnoreCase("Heads")) { //compares H or Heads with the tokens in file ignoring lower case and upper case differences

           head++;                } //if a token i.e. any form of heads in file matches with the H or Heads then add 1 to the number of heads

           count++;            } //increment to 1 to compute total number of counts

double result = Percentage(head, count); //calls Percentage method passing number of heads and total counts to compute the percentage of heads

System.out.println(head + " heads " + "(" + result +"%)"); // prints the number of heads

if(result >= 50.00) { //if the percentage is greater or equal to 50

System.out.println("You win!");} //displays this message if above if condition is true

else //if the percentage is less than 50

{System.out.println("You lose!");}  }    } //displays this message if above if condition is false

public static double Percentage(int h, int total) { //method to compute the percentage of heads

double p = (double)h/total* 100; // divide number of heads with the total count and multiply the result by 100 to compute percentage

return p;    } } //returns result

Explanation:

The program is well explained in the comments mentioned with each line of the above code. I will explain how the method coinFlip  works.

Method coinFlip accepts a string holding a file name as its parameter. It opens that file and reads its contents as a sequence of tokens. Then it reads and scans through each token and the if condition statement:

if (token.equalsIgnoreCase("H")||token.equalsIgnoreCase("Heads"))

checks if the each token in the sequence stored in the file is equal to the H or Heads regardless of the case of the token. For example if the first token in the sequence is H then this if condition evaluates to true. Then the head++ statement increments the count of head by 1. After scanning each token in the sequence the variable count is also increased to 1.

If the token of the sequence is HeAds then this if condition evaluates to true because the lower or upper case difference is ignored due to equalsIgnoreCase method. Each time a head is found in the sequence the variable head is incremented to 1.

However if the token in the sequence is Tails then this if condition evaluates to false. Then the value of head variable is not incremented to 1. Next the count variable is incremented to 1 because this variable value is always incremented to 1 each time a token is scanned because count returns the total number of tokens and head returns total number of heads in the tokens.

Percentage method is used to return the percentage of the number of heads in the sequence. It takes head and count as parameters (h and total). Computes the percentage by this formula h/total* 100. If the result of this is greater than or equal to 50 then the message  You win is displayed otherwise message You lose! is displayed in output.

Write A Method Named CoinFlip That Accepts As Its Parameter A String Holding A File Name, Opens That

Related Questions

the base on which the number n=(34)? is written if it has a value of n= (22)10​

Answers

If I'm understanding the question correctly, you are looking for an integer b (b ≠ 0, b ≠ 1) such that

[tex]34_b = 22_{10}[/tex]

In other words, you're solving for b such that

b ¹ + 4×b ⁰ = 22

or

3b + 4 = 22

Solving this is trivial:

3b + 4 = 22

3b = 18

b = 6

So we have

34₆ = 22₁₀

Show using a cross-product construction that the class of regular languages is closed under set difference. You do not need an inductive proof, but you should convincingly explain why your construction works.

Answers

Answer:

The class definition for Javascript:

var Class = {

      arguments of the class object are initialized here;

}

This class definition for Python:

class "class_name"( object ):

      def __init__(self, arguments are passed are and initialized after the closing parenthesis)

Explanation:

Object-oriented programming languages are vital tools in creating data structures that are meant to be changeable, unindexed but directly accessible knowing the key value, and has unique membership.

This clearly is an adoption of the set data structure rule in creating a data structure blueprint that can be instantiated anytime in the code.

Which type of user profile is stored in the C:\Users folder and is automatically created when a user logs on to the computer for the first time?

Answers

Answer:

a. Local user profile.

Explanation:

Local user profile is a type of user profile which is stored in the C:\Users folder and is automatically created when a user logs on to the computer for the first time and it is being stored on the local hard disk of the computer.

Generally, in Microsoft windows any change made to the local user profile is peculiar to the user and the host computer on which the change is made.

Hence, local user profiles avails several users the opportunity of sharing a single computer with their respective user settings and data.

The first electric, general-purpose computer, ENIAC, was programmed by calculating algorithms on paper entering code directly into the computer flipping switches by hand using MS-DOS as the operating system

Answers

Complete Question:

The first electric, general-purpose computer, ENIAC, was programmed by?

Group of answer choices.

A. Calculating algorithms on paper.

B. Entering code directly into the computer.

C. Flipping switches by hand.

D. Using MS-DOS as the operating system.

Answer:

C. Flipping switches by hand.

Explanation:

The first electric, general-purpose computer, ENIAC, was programmed by flipping switches by hand.

ENIAC is an acronym for Electronic Numerical Integrator and Computer, it was developed in 1945 by John Mauchly and J. Presber Eckert. ENIAC was used for solving numerical problems or calculation-related tasks by the process of reprogramming.

In order to give the ENIAC a series of machine instructions to follow in the execution of a task, the programmers had to undergo the cumbersome procedure of connecting, removing, reconnecting cables and flipping switches by hand because data couldn't be stored in memory.

The POR is a systematic method of documentation that includes a database, problem list, initiitial plan and progress notes.
A. True
B. False

Answers

Explanation:

The POR is a systematic method of documentation that includes a database, problem list, initiitial plan and progress notes is true

A good machine should have the mechanical advantage of......?​

Answers

Answer:

The ideal mechanical advantage (IMA) of an inclined plane is the length of the incline divided by the vertical rise, the so-called run-to-rise ratio. The mechanical advantage increases as the slope of the incline decreases, but then the load will have to be moved a greater distance.

Explanation:

is there similarities between plagiarism and software piracy? explain.​

Answers

PlagiarismPlagiarism means using someone else's ideas or words without crediting source.PiracyPiracy is unauthorized use, reproduction, or sharing of copyrighted material.

Determine the median paycheck from the following set:

{$100, $250, $300, $400, $600, $650}

$300

$350

$450

$600

Answers

Answer:

My answer to the question is $350.

The middle numbers are $300&$400.

300+400=700/2=350.

Answer:

$350

Explanation:

What is also known as computer Network?

Answers

The best-known computer network is the Internet. Network computer devices that originate, route and terminate the data are called network nodes. Nodes can include hosts such as personal computers, phones,servers as well as networking hardware.

is badlion safe and how ?

Answers

Answer:

Yes, badlion is safe. The further explanation is given below.

Explanation:

Badlion Client does not encompass any malicious programs, like viruses and sometimes malware.Badlion application is pretty much safe to be used on inequality in society because most expressly forbidden plugins like decided to post as well as schematics become unavailable on the client-side whenever you enter Hypixel, but that is not a confirmation and therefore should not be depended towards.

Strong emotions can interfere with your ability to
A. make wise decisions.
B. think and reason.
C. judge risks.
D. all of the above

Answers

All of the above

All emotions cloud judgement, but anger is the worst

Hope this helps ♥︎

Strong emotions can interfere with your ability to make wise decisions, think and reason, and judge risk. The correct option is (D).

Strong emotions can indeed interfere with a person's ability to make wise decisions, think clearly and reason logically, and accurately judge risks.

Emotions have the potential to cloud judgment, bias perception, and impede rational thinking, which can impact decision-making processes.

Therefore, Strong emotions can interfere with your ability to make wise decisions, think and reason, and judge risk. The correct option is (D).

To know more about the emotions:

https://brainly.com/question/14587591

#SPJ4

In what tab can a user find the workspace option?

Answers

D. View.
You can find the workspace and preview of the file in View.


A high school in a low-income area offers special programs to help students acquire the technical skills needed to find jobs as computer technicians
This program is most strongly related to which aspect of life?

Answers

Answer:

Economy

Explanation:

Education geared towards readying students to become an employable technician or becoming skilled in a particular craft are known as vocational education. Vocational education, otherwise known as career and technical education is provided by a vocational school

It is suggested that there should be wider range of educational coverage between higher education and vocational educational due to the increasing importance of the use of technology in the workplace

As such technical vocational education is generally taken as an important tool to grow the economy while particularly reducing the unemployment among the youth.

within the report wizard which of the following would you change in order to view a report in landscape orientation

Answers

Answer: page orientation

Explanation:

GIVING BRANLIEST IFFF CORRECT James uses a database to track his school football team. Which feature in a database allows James to list only the players that didn't play in the last game? Title Filter Search Sort

Answers

Answer:

filter

Explanation:

the filter feature allows him to fetch data that only meets a certain criteria(those who didn't play in the last game)

The FILTER feature in a database allows James to list on the players that did not play in the game.

What is the filter feature in EXCEL?

The FILTER feature in Excel is used to clear out a number of statistics primarily based totally on the standards which you specify. The feature belongs to the class of Dynamic Arrays functions.

The end result is an array of values that mechanically spills into a number cells, beginning from the Cells wherein you input a formula.

Thus, The FILTER feature in a database allows James to list on the players that did not play in the game.

Learn more about FILTER feature here:

https://brainly.com/question/11866402

#SPJ2

Which recovery method helps users boot into an environment to get them back into the system so they can begin the troubleshooting process

Answers

Answer:

sfadasda

Explanation:

dsadasdadas

Which octet of the subnet mask 255.255.255.0 will tell the router the corresponding host ID?The last octetThe first octetThe first and last octetThe middle two octets

Answers

Answer:

The last octet

Explanation:

Here in the question, given the sub net mask, we want to know which octet of the subnet mask will tell the router the corresponding host ID.

The correct answer to this is the last octet. It is the last octet that will tell the router the corresponding host ID

Suppose a Huffman tree is to be built for 5 characters. Give a set of 5 characters, and their distinct probabilities (no duplicates), that would result in the tallest possible tree. Show the tree. Derive the average code length: write the expression, you don't have to simplify it down to a single value.

Answers

I love chipotle do you live chipotle

How does the teacher know you have completed your assignment in Google Classroom?

Answers

Answer:

When students have completed the assignment, they simply click the Mark As Done button to let the teacher know they have finished.

Explanation: Note: The teacher does NOT receive an alert or email notification when work has been turned in, or marked as done.

Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 2, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by " seconds". End with a newline. Example output for ounces = 7:
42 seconds
import java.util.Scanner;
public class PopcornTimer {
public static void printPopcornTime(int bagOunces) {
/* Your solution goes here */
}
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int userOunces;
userOunces = scnr.nextInt();
printPopcornTime(userOunces);
}
}

Answers

Answer:

Replace

/* Your solution goes here */

with

if (bagOunces < 2) {

   System.out.print("Too Small");

}

else if(bagOunces > 10) {

   System.out.print("Too Large");

}

else {

   System.out.print((bagOunces * 6)+" seconds");

}

Explanation:

This line checks if bagOunces is less than 2;

if (bagOunces < 2) {

If yes, the string "Too Small" is printed

   System.out.print("Too Small");

}

This line checks if bagOunces is greater than 10

else if(bagOunces > 10) {

If yes, the string "Too Large" is printed

   System.out.print("Too Large");

}

The following condition is executed if the above conditions are false

else {

This multiplies bagOunces by 6 and adds seconds

   System.out.print((bagOunces * 6)+" seconds");

}

Consider two different processors P1 and P2 executing the same instruction set. P1 has a 3 GHz clock rate and a CPI of 1.5. P2 has a 3 GHz clock rate and a CPI of 1.0. Which processor has the highest performance expressed in instructions per second

Answers

Answer:

Processor P2 has the highest performance expressed in instructions per second.

Explanation:

Given:

Processors:

P1

P2

Clock rate of P1 = 3 GHz

Clock rate of P2 = 3 GHz

Cycles per instruction = CPI of P1 = 1.5

Cycles per instruction = CPI of P2 = 1.0

To find:

which processor has the highest performance in instructions per second (IPS)

Solution:

Compute CPU time:

CPU time =  (Number of instructions * cycles per instruction) / clock rate

CPU time = (I * CPI) / R

We are given the CPI and clock rate. So

CPU time = (I * CPI) / R

 I / CPU time = R/CPI

Since

Instructions per second = Number of instructions (I) / execution time

                             IPS     = I / CPU time

So

Instructions Per Second = clock rate / cycles per instruction

IPS = R/CPI

Putting the values in above formula:

Instructions Per Second for P1 = IPS (P1)

                                                  = clock rate P1 / CPI (P1)

                                                  = 3 GHz / 1.5

                                     IPS (P1) = 2            

As 1 GHz = 10⁹ Hz

IPS (P1) = 2x10⁹

Instructions Per Second for P2 = IPS (P2)

                                                  = clock rate P2 / CPI (P2)

                                                  = 3 / 1.0

                                     IPS (P2) = 3

As 1 GHz = 10⁹ Hz

IPS (P2) = 3x10⁹

Hence processor P2 has the highest performance expressed in instructions per second i.e. 3x10⁹

When we have signals within 1-2 MHz band, using a waveguide is the most preferred choice for a transmission line. T or F?​

Answers

Answer:

T

Explanation:

Review the given requirements using the checklist and discover possible problems with them. The following requirements are for a library system which is an interactive system providing access to a large document database and which allows the automated ordering and electronic delivery of documents to local and remote end-users. Some requirements for this system are: Req. 1 The user interface shall be html. Users shall access the system via standard web browsers such as Netscape and Internet Explorer. Req. 2 The system shall primarily an end-user system. Users shall use the system within the constraints of the permissions assigned by the administrator to identify, locate, order and receive documents. Req. 3 Users shall communicate with the system mainly via the html interface. Req. 4 User shall provide input to the system via the html interface. Req. 5 The system shall give output to the user via the html interface, email and print. The print output shall mainly be documents.

Answers

Answer:

Redundancy

Req. 1 and Req. 3 are seemed to say the same thing. We need to remove the first sentence in Req. 1

Conflict and understandability

Req. 1 states that access is through web browser while Req. 4 states that access is via html. We have to re-write the Req. 3 to make it clear that users do not actually have to write directly html to communicate with the system.

Completeness

Req. 5 states that print out will “mainly” be documents. What else might be printed? What other inputs will be produced?

Either remove mainly or clarify other print out.

What version of html or web browser is assumed in Req. 1 and Req. 3?

Explanation:

Software that is used to obtain private user information such as a user's keystrokes or copies of e-mail is referred to as: Question 6 options: A) botnet B) adware. C) a backdoor. D) spyware.

Answers

Answer:

The correct answer is D) Spyware.

Explanation:

Also known as a Malicious Software (or Malware for short), a Spyware is designed to gain unsolicited entrance into ones computer and when executed, performs the function of illegally stealing one's private information and sending them to the hacker or originator of the software.

The following have been identified as spyware threats:

Transponder (vx2) Hot as HellBlazeFindInternet Optimizer

Cheers!

A user in an apartment building on a wireless network is no longer able to print to the network printer. The user has been able to print to the printer in the past and nothing on the network has changed. A technician notices that the user has a different IP address scheme than what was originally setup and is able to browse the Internet using that IP address scheme. What should he do?

Answers

Answer:

The technician should either provide a route from the user's IP scheme to the printer or change the user's IP scheme to be within the same scheme as the printer.

Explanation:

The most likely reason the user is unable to print to the printer is that the user's computer cannot path the current address to the address of the printer.  Without the printer being on the same subnet as the user's computer, the computer has no way of being able to tell where the printer is.

The two solutions to this are to either add a route to the user's computer explicitly telling the user's computer where to trace to find the printer or to change the user's computer to match the IP scheme of the printer.

Cheers.

Write a pseudocode For loop that displays all the numbers from 0 to 5, one at a time. We have the following pseudocode so far. Declare Integer number Write this statement Display number End For Type the exact text for the line of pseudocode that should replace Write this statement shown above.

Answers

Answer:

The statement is:

For number = 0 to 5

Explanation:

Given

The incomplete pseudocode

Required

The loop statement to complete the pseudocode

To loop from 0 to 5, we make use of:

For number = 0 to 5

Where:

number is the integer variable declared on line 1

So, the complete pseudocode is:

Declare Integer number

For number = 0 to 5

Display number

End For

Does the cloud solution offer equal or greater data security capabilities than those pro-vided by your organization’s data center?

Answers

Answer:I think greater. Answer my question that I posted plz

Explanation:

Which one is the result of the output given by a computer
I​

Answers

Explanation:

Instruction , data and information all of these.

Write down the complete AJAX code to avoid page caching.

Answers

Answer:

AZAX is key sentence for without reloading page.

Explanation:

AJAX is also known as XHR. If some one wants to send the file without reloading then look ahead at the search function and prompt the users by auto saving the documents. This request is sent to the server. The server return the data to your network. Whenever you have seen the file form, some action on the page. You will see some request from AJAX server request on your functional area. AJAX is called a reloading file without page. AZAX is stands for Asynchronous java scripts And XML. AJAX is used to send an email. AZAX is not used in front end, it is used from back end process.

Objects for AJAXJava ScriptWord Press Action.ProtectionError handling process

This method adds newValue to the list at the specified index. If the index is invalid for the list, throw an IndexOutOfBoundsException. Note that the last valid index is the size of the list; this would mean adding to the back of the list. Call any existing methods of LinkedList and LLNode as needed.

Answers

Answer:

i dont know

Explanation:

Other Questions
How can I find friend from abroad ? Atmospheric air at 1 atm has a dry-bulb temperature of 20C and a wet-bulb temperature of 15C. Determine the dew point temperature Two trains are moving towards each other on the same railroad track. From this track there's an offshoot piece of railroad the length of which is shorter than the length of the train but longer than the length of one train car. How can the trains pass each other? 8. A home inspection performed by a licensed inspector isO a. a limited visual survey and basic performance evaluation of systems in house.ob. a full visual survey to ensure the house meets building code standards.c. a comprehensive investigation of the house using specialized equipment.o d. an exploratory probe to determine the cause or effect of deficiencies noted. trong cng mt nhit , lng nng lng trn mi mol ca cht kh no ln nhta) Kh n nguyn tb) Kh c t ba nguyn tc) Kh lng nguyn t We want to build a swimming pool that is 2m by 6m. On our page it measured out to be 8cm by 24cm. What is tge scale that can be used Describe in words how you would solve the linear system y = 3x + 1 and y = - 2x + 3. Perhaps you wanted pizza for dinner, but were out voted by the rest of the family who wanted chili. This is similar to what happens in a community. One person has to give up a right for the good of the group. Sometimes citizens' duties and rights conflict with each other. A good example is a public protest. People have the right to meet in groups and share ideas. However, a protest can disrupt traffic or other normal activities. A city must provide extra police protection to keep people safe. Therefore, the city has the right to require permission in advance for a protest. Government must make laws to balance the rights of individuals and different groups of people.What signal word or phrase indicates there is a comparison in this paragraph? Were outvoted by Is similar to With each Or otherYou must check the box below prior to submitting your exam! Check this box to indicate you are ready to submit your examFDK391.12 Determine the number of degrees of freedom for the two-sample t test or CI in each of the following situations. (Round your answers down to the nearest whole number.)(a) m = 12, n = 15, s1 = 4.0, s2 = 6.0 (b) m = 12, n = 21, s1 = 4.0, s2 = 6.0(c) m = 12, n = 21, s1 = 3.0, s2 = 6.0(d) m = 10, n = 24, s1 = 4.0, s2 = 6.0 Solve for x.3x + 22x + 6x = [?] This problem is very difficult I have been stuck on it the whole entire test Select the correct text in the passage.Which detail best develops the central idea?The Footprints of Timeby Charles Bancroft(excerpt from Section VI. The Roman Republic) Which of the following is not a way to help your community improve its environmental impact?A. Buy goods in the largest boxes possibleB. Choose to purchase biodegradable productsC. Drink from a reusable water bottle D. Use a natural household cleaner like vinegar What is the degree of the monomial 5x^4? A. Degree 20 B. Degree 5 C. Degree 9 D. Degree 4 I need help with VOCAB!!!Please help ASAP please please help!! If you have a piece of glass that is 12in X 12in - how many square feet is it? Cul es la importancia de leer y escribir en la universidad? En qu forma interpretas leer y escribir en un mundo cambiante como el que vives? Cmo valoras tu capacidad lectora? Qu elementos influyen en tu habilidad para leer y escribir ahora que inicias tu formacin universitaria? FINAL QUESTION!!! EASY I AM JUST NOT TO SURE.. GOT 8 MINUTES LEFT!!! AT LEAST COME LOOK !!! WILL GIVE BRANLIEST!!14. __________ is when the mind supports the efforts of the body and vice versa.A) Total fitnessB) Heart rateC) Muscle toneD) Strength-building Using the formula D = s:t where D equals distance traveled, r equals the average rate ofspeed, and t equals the time traveled, choose the expression or equation that correctlyrepresents this information.Mary drove 150 miles in three hours. What was her average rate of speed?=150 = 3r = 3 = 150O p + 150 3 A premature infant develops jaundice. Laboratory test results are negative for hemolytic disease of the newborn, but the infants bilirubin level continues to rise. Abnormal urinalysis test results include a dark yellow color, positive Ictotest, and needle-shaped crystals seen on microscopic examination. What is the most probable cause of the infants jaundice?