1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Luden [163]
4 years ago
10

java Write a program that simulates tossing a coin. Prompt the user for how many times to toss the coin. Code a method with no p

arameters that randomly returns either the String "heads"or the string "tails". Call this method in main as many times as requested and report the results.
Engineering
2 answers:
igomit [66]4 years ago
5 0

Answer:

The source code to this question has been attached to this response. Please download it and go through the code.

The source code contains comments explaining important segments of the code. Kindly read the comments carefully for better readability and understandability of the code.

Download java
max2010maxim [7]4 years ago
4 0

Answer:

The solution code is written in Java.

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        Scanner inNum = new Scanner(System.in);
  4.        System.out.print("Enter number of toss: ");
  5.        int num = inNum.nextInt();
  6.        for(int i=0; i < num; i++){
  7.            System.out.println(toss());
  8.        }
  9.    }
  10.    public static String toss(){
  11.        String option[] = {"heads", "tails"};
  12.        Random rand = new Random();
  13.        return option[rand.nextInt(2)];
  14.    }
  15. }

Explanation:

Firstly, we create a function <em>toss()</em> with no parameter but will return a string (Line 14). Within the function body, create an option array with two elements, "heads" and "tails" (Line 15). Next create a Random object (Line 16) and use <em>nextInt()</em> method to get random value either 0 or 1. Please note we need to pass the value of 2 into <em>nextInx() </em>method to ensure the random value generated is either 0 or 1.  We use this generate random value as an index of <em>option </em>array and return either "heads" or "tails" as output (Line 17).

In the main program, we create Scanner object and use it to prompt user to input an number for how many times to toss the coin (Line 6 - 7). Next, we use the input num to control how many times a for loop should run (Line 9). In each round of the loop, call the function <em>toss() </em>and print the output to terminal (Line 10).  

You might be interested in
What is the difference between a cost and a benefit?
goblinko [34]

Answer:

A cost is something you have to give up or sacrifice and a benefit is something that is gained or is helpful.

Explanation:

In a cost-benefit analysis of a system, an engineer is to simply look at the requirements for the system and determine the costs to build the system, both in financial value and energy value.  Additionally, the engineer needs to determine the benefits that would come from choosing a particular path of cost.  If the benefits outweigh the cost for the project, then the solution is accepted.  Else, the cost outweighs the benefit and the solution is rejected.

6 0
3 years ago
Find the remaining trigonometric function of 0 if
amm1812

Answer:

Hope this will help you

have a great day

8 0
3 years ago
Legal metrology would protect consumers from businesses that do not take measurements according to defined measuring regulations
sergij07 [2.7K]

From what my research concluded, true

5 0
4 years ago
What advantage might there be to having the encoder located on the motor side of the gearhead instead of at the output shaft of
pickupchik [31]

The most accurate answer to that process is definitely precision. The Rotary encoder is an electro-mechanical device that converts the angular position or motion of a shaft or axle to analog or digital output signals. The efficiency of these devices is subject to the position and angle of the axis in front of the encoder.

Most cars use reduction systems in their gearboxes that convert a certain signal input into an output. Mechanically for example, a 20: 1 reduction box already infers that if there is a revolution in the input at the output there are 20. That same transferred to the encoder pulses would imply greater precision.

For example a decoder with 50 holes would have to read 1000 pulses (50 * 20) which is basically a degree of accuracy of 0.36 degrees. In this way it is possible to conclude that if the assembly of the encoder is carried out next to the motor and not at the output, it can be provided with greater precision at the time of reading.

7 0
4 years ago
Determine the carburizing time necessary to achieve a carbon concentration of 0.30 wt% at a position 4 mm into an iron–carbon al
Ahat [919]

Answer:

the carburizing time necessary to achieve a carbon concentration is 31.657 hours

Explanation:

Given the data in the question;

To determine the carburizing time necessary to achieve the given carbon concentration, we will be using the following equation:

(Cs - Cx) / (Cs - C0) = ERF( x / 2√Dt)

where Cs is Concentration of carbon at surface = 0.90

Cx is Concentration of carbon at distance x = 0.30 ; x in this case is 4 mm = ( 0.004 m )

C0 is Initial concentration of carbon = 0.10

ERF() = Error function at the given value

D = Diffusion of Carbon into steel

t = Time necessary to achieve given carbon concentration ,

so

(Cs - Cx) / (Cs - C0) = (0.9 - 0.3) / (0.9 - 0.1)

= 0.6 / 0.8

= 0.75

now, ERF(z) = 0.75; using ERF table, we can say;

Z ~ 0.81; which means ( x / 2√Dt) = 0.81

Now, Using the table of diffusion data

D = 5.35 × 10⁻¹¹ m²/sec at (1100°C) or 1373 K

now we calculate the carbonizing time by using the following equation;

z = (x/2√Dt)

t is carbonizing time

so we we substitute in our values

0.81 = ( 0.004 / 2 × √5.35 × 10⁻¹¹ × √t)

0.81 = 0.004 / 1.4628 × 10⁻⁵ × √t

0.81 × 1.4628 × 10⁻⁵ × √t = 0.004

1.184868 × 10⁻⁵ × √t = 0.004  

√t = 0.004 / 1.184868 × 10⁻⁵

√t = 337.5903

t = ( 337.5903)²  

t = 113967.21 seconds

we convert to hours

t = 113967.21 / 3600

t = 31.657 hours

Therefore, the carburizing time necessary to achieve a carbon concentration is 31.657 hours

7 0
3 years ago
Other questions:
  • ) A 20 ft horizontal beam is attached to a wall with a fixed support. If the beam is subjected to the distributed loads indicate
    12·1 answer
  • A particular motor rotates at 3000 revolutions per minute. What is its speed in rad/sec, and how many seconds does it takes to m
    5·1 answer
  • The minimum size for overhead service conductors shall not be smaller than ____ AWG copper. A. 4 B. 6 C. 8 D. 10
    13·1 answer
  • The annual average of solar photovoltaic energy in Phoenix is 6,720
    8·1 answer
  • A misfire code is a type ____ DTC<br> A) 1 or 2<br> B) a or b<br> C) c or d<br> D l or ll
    15·1 answer
  • What kinds of problems or projects would a mechanical engineer work on?
    11·1 answer
  • If the hypotenuse of a right triangle is 12 and an acute angle is 37 degrees find leg a and leg b lengths
    9·1 answer
  • HELP ASSAPPP
    15·1 answer
  • Which of the following procedures best applies to assessing the embodied energy of a building?
    12·1 answer
  • 1- The preexponential and activation energy for the diffusion of iron in cobalt are 1.1×10-5 m 2 /s and 253,300 J/mol, respectiv
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!