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]
3 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]3 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]3 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
Which of the following uses pressure and flow to transmit power from one location to another?
lord [1]

Answer:

fluid power

Explanation:

fluids commonly used in fluid power are Oil, Water, Air, CO², and Nitrogen gas, fluid power is commonly confused with hydraulic power, which only uses liquids, fluid power uses either liquids or gases

5 0
2 years ago
Using a forked rod, a 0.5-kg smooth peg P is forced to move along the vertical slotted path r = (0.5 θ) m, whereθ is in radians.
-BARSIC- [3]

Answer:

N_c = 3.03 N

F = 1.81 N

Explanation:

Given:

- The attachment missing from the question is given:

- The given expressions for the radial and θ direction of motion:

                                       r = 0.5*θ

                                       θ = 0.5*t^2              ...... (correction for the question)

- Mass of peg m = 0.5 kg

Find:

a) Determine the magnitude of the force of the rod on the peg at the instant t = 2 s.

b) Determine the magnitude of the normal force of the slot on the peg.

Solution:

- Determine the expressions for radial kinematics:

                                        dr/dt = 0.5*dθ/dt

                                        d^2r/dt^2 = 0.5*d^2θ/dt^2

- Similarly the expressions for θ direction kinematics:

                                        dθ/dt = t

                                        d^2θ/dt^2 = 1

- Evaluate each at time t = 2 s.

                                        θ = 0.5*t^2 = 0.5*2^2 = 2 rad -----> 114.59°

                                        r = 1 m , dr / dt = 1 m/s , d^2 r / dt^2 = 0.5 m/s^2

- Evaluate the angle ψ between radial and horizontal direction:

                                        tan Ψ = r / (dr/dθ) = 1 / 0.5

                                        Ψ = 63.43°

- Develop a free body diagram (attached) and the compute the radial and θ acceleration:

                                        a_r = d^2r / dt^2 - r * dθ/dt

                                        a_r = 0.5 - 1*(2)^2 = -3.5 m/s^2

                                        a_θ =  r * (d^2θ/dt^2) + 2 * (dr/dt) * (dθ/dt)

                                        a_θ = 1(1) + 2*(1)*(2) = 5 m/s^2

- Using Newton's Second Law of motion to construct equations in both radial and θ directions as follows:

Radial direction:              N_c * cos(26.57) - W*cos(24.59) = m*a_r

θ direction:                      F  - N_c * sin(26.57) + W*sin(24.59) = m*a_θ

Where, F is the force on the peg by rod and N_c is the normal force on peg by the slot. W is the weight of the peg. Using radial equation:

                                       N_c * cos(26.57) - 4.905*cos(24.59) = 0.5*-3.5

                                       N_c = 3.03 N

                                       F  - 3.03 * sin(26.57) + 4.905*sin(24.59) = 0.5*5

                                       F = 1.81 N

4 0
3 years ago
Which of the following Identifies the challenges faced by scientists experimenting with using artificial photosynthesis as
bezimeni [28]

Answer:

The cost and size of materials needed to produce energy

Explanation:

Artificial photosynthesis is a chemical process that uses solar cells instead of chlorophyll to absorb sunlight and convert it into electricity. This process uses artificial leaves that require man-made catalyst to spilt water present in the air into hydrogen and oxygen. It is clear that the reaction requires heat from the sun for energy production thus the technology is expensive to be applied in most areas of the world. Additionally, results obtained from previous undertaken projects of this type has been ineffective and unsustainable because it involves a lot of trial and error.

8 0
2 years ago
Interpret the assembly program below: MOV R3,R0;
Reika [66]

Answer:

Explanation:

1.  With the operands R0, R1, the program would compute AND operation and ADD operation .

2. The operands could truly be signed 2's complement encoded (i.e Yes) .

3. The overflow truly occurs when two numbers that are unsigned were added and the result is larger than the capacity of the register, in that situation, overflow would occur and it could corrupt the data.

 When the result of an operation is smaller in magnitude than the smallest value represented by the data type, then arithmetic underflow will occur.

7 0
3 years ago
10 POINTS!!
marusya05 [52]

Answer:

disable yahoo from activating.

Explanation:

 either force quit it or add chrome to your user bar at the bottom of the screen (if ure on a computer) if yahoo is on ur bar make sure to force quit it by right clicking and clicking "force quit" and it should stop

5 0
3 years ago
Other questions:
  • 6.15. In an attempt to conserve water and to be awarded LEED (Leadership in Energy and Environmental Design) certification, a 20
    14·1 answer
  • 8–21 Heat in the amount of 100 kJ is transferred directly from a hot reservoir at 1200 K to a cold reservoir at 600 K. Calculate
    6·1 answer
  • Viscous effects are negligible outside of the hydrodynamic boundary layer. (3 points) a. True b. False
    5·1 answer
  • Which of the following drivers has the right-of-way?
    9·1 answer
  • Water is the working fluid in an ideal Rankine cycle. Saturated vapor enters the turbine at 12 MPa, and the condenser pressure i
    8·2 answers
  • Which of the following is an example of a reliable source?
    10·1 answer
  • A compound machine contains three simple machines with IMAs of 2, 4 and 5, respectively. What is the overall ideal mechanical ad
    15·1 answer
  • 3. (20 points) Suppose we wish to search a linked list of length n, where each element contains a key k along with a hash value
    7·1 answer
  • You talk with the owner and he likes the idea of using two large glulam beams as shown to carry the joist loads. Design the glul
    5·1 answer
  • What are difference between conic sectional and solids?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!