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
An electric power plant uses solid waste for fuel in the production of electricity. The cost Y in dollars per hour to produce el
andrew-mc [135]

Answer:

15.64 MW

Explanation:

The computation of value of X that gives maximum profit is shown below:-

Profit = Revenue - Cost

= 15x - 0.2x 2 - 12 - 0.3x - 0.27x 2

= 14.7x - .47x^2 - 12

After solving the above equation we will get maximum differentiate  for profit that is

14.7 - 0.94x = 0

So,

x = 15.64 MW

Therefore for computing the value of X that gives maximum profit we simply solve the above equation.

8 0
4 years ago
For the following conditions determine whether a CMFR or a PFR is more efficient in removing a reactive compound from the waste
andrew11 [14]

Answer:

The PFR is more efficient in the removal of the reactive compound as it has the higher conversion ratio.

Xₚբᵣ = 0.632

X꜀ₘբᵣ = 0.5

Xₚբᵣ > X꜀ₘբᵣ

Explanation:

From the reaction rate coefficient, it is evident the reaction is a first order reaction

Performance equation for a CMFR for a first order reaction is

kτ = (X)/(1 - X)

k = reaction rate constant = 0.05 /day

τ = Time constant or holding time = V/F₀

V = volume of reactor = 280 m³

F₀ = Flowrate into the reactor = 14 m³/day

X = conversion

k(V/F₀) = (X)/(1 - X)

0.05 × (280/14) = X/(1 - X)

1 = X/(1 - X)

X = 1 - X

2X = 1

X = 1/2 = 0.5

For the PFR

Performance equation for a first order reaction is given by

kτ = In [1/(1 - X)]

The parameters are the same as above,

0.05 × (280/14) = In (1/(1-X)

1 = In (1/(1-X))

e = 1/(1 - X)

2.718 = 1/(1 - X)

1 - X = 1/2.718

1 - X = 0.3679

X = 1 - 0.3679

X = 0.632

The PFR is evidently more efficient in the removal of the reactive compound as it has the higher conversion ratio.

3 0
3 years ago
What is the volume of the rectangular prism shown.
Likurg_2 [28]
It would be 72cm bc u need to add up all the line in the back to
7 0
3 years ago
What is the built-in pollution control system in an incinerator called
Kobotan [32]

Explanation:

hbyndbnn☝️

7 0
3 years ago
Using the celsius_to_kelvin function as a guide, create a new function, changing the name to kelvin_to_celsius, and modifying th
aleksandr82 [10.1K]

Answer:

# kelvin_to_celsius function is defined

# it has value_kelvin as argument

def kelvin_to_celsius(value_kelvin):

   # value_celsius is initialized to 0.0

   value_celsius = 0.0

   

   # value_celsius is calculated by

   # subtracting 273.15 from value_kelvin

   value_celsius = value_kelvin - 273.15

   # value_celsius is returned

   return value_celsius

   

# celsius_to_kelvin function is defined

# it has value_celsius as argument

def celsius_to_kelvin(value_celsius):

   # value_kelvin is initialized to 0.0

   value_kelvin = 0.0

   

   # value_kelvin is calculated by

   # adding 273.15 to value_celsius

   value_kelvin = value_celsius + 273.15

   # value_kelvin is returned

   return value_kelvin

   

value_c = 0.0

value_k = 0.0

value_c = 10.0

# value_c = 10.0 is used to test the function celsius_to_kelvin

# the result is displayed

print(value_c, 'C is', celsius_to_kelvin(value_c), 'K')

value_k = 283.15

# value_k = 283.15 is used to test the function kelvin_to_celsius

# the result is displayed

print(value_k, 'is', kelvin_to_celsius(value_k), 'C')

Explanation:

Image of celsius_to_kelvin function used as guideline is attached

Image of program output is attached.

4 0
3 years ago
Other questions:
  • Write a function digits() that accepts a non-negative integer argument n and returns the number of digits in it’s decimal repres
    13·1 answer
  • A certain process requires 3.0 cfs of water to be delivered at a pressure of 30 psi. This water comes from a large-diameter supp
    9·1 answer
  • Cold water (cp = 4180 J/kg·K) leading to a shower enters a thin-walled double-pipe counterflow heat exchanger at 15°C at a rate
    11·1 answer
  • -0-1"<br> -0<br> -20<br> -15<br> -10<br> 0<br> -5
    9·1 answer
  • The application of technology results in human-made things called
    9·1 answer
  • Which of these are factors of 121?
    13·2 answers
  • Technician A says that squeeze-type resistance spot welding (STRSW) may be used on open butt joints. Technician B says that repl
    14·1 answer
  • What is the name for a program based on the way your brain works?
    13·2 answers
  • Which cod is the best whoever has the best awnser gets brainliest​
    12·1 answer
  • What do you mean by overflow and underflow error in array?.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!