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
On July 23, 1983, Air Canada Flight 143 required 22,300 kg of jet fuel to fly from Montreal to Edmonton. The density of jet fuel
Natasha2012 [34]

Answer:

20, 083 L

Explanation:

The mistake was the result of not using units when converting the 7862 l to Kg. They used the density in pounds hence they multiplied by 1.77 Lb/L and obtained 13597 Lb not Kg as they assumed.

To obtain the amount needed to refuel they subtracted this quantity from the 22,300 Kg required for the trip again obtaining the wrong quantity of 8703 Kg and they converted this to liters by dividing the density to get 4916 L and then placed then 5000 L of fuel

The quantity required was

7862 L * 1.77 Lb/L = 13915.74 Lb (pounds not kilos)

then converting this pounds to Kg by multiplying by  0.454 Kg/L one gets

6173 Kg on board

Amount Required

( 22,300 -6173)  :  16127 Kg

16127 Kg/ 0.803 Kg/L =  20083 L

5 0
3 years ago
Technician A says that squeeze-type resistance spot welding (STRSW) may be used on open butt joints. Technician B says that repl
Mamont248 [21]

Answer:

B only

Explanation:

Squeeze-type resistance spot welding (STRSW)is a type of electric resistance welding that brings about the weld on interfacing sheet metal pieces through which heat generated from electric resistance bring about fusion and welding of the two pieces together

Therefore, it is not meant for opening but joints but it can be used for making replacement spot welds adjacent to the original spot weld due to the smaller heat affected zone (HAZ) created by the STRSW process.

6 0
3 years ago
Consider a modification of the air-standard Otto cycle in which the isentropic compression and expansion processes are each repl
Ulleksa [173]

Answer:

The answers to the question are

(1) Process 1 to 2

W = 295.16 kJ/kg

Q = -73.79 kJ/kg

(2) Process 2 to 3

W = 0

Q = 1135.376 kJ/kg

(3) Process 3 to 4

W = -1049.835 kJ/kg

Q = 262.459 kJ/kg

(4) Process 4 to 3

W=0

Q = -569.09 kJ/kg

(b) The thermal efficiency = 49.9 %

(c) The mean effective pressure is 9.44 bar

Explanation:

(a) Volume compression ratio \frac{v_1}{v_2}  = 10

Initial pressure p₁ = 1 bar

Initial temperature, T₁ = 310 K

cp = 1.005 kJ/kg⋅K

Temperature T₃ = 2200 K from the isentropic chart of the Otto cycle

For a polytropic process we have

\frac{p_1}{p_2}  = (\frac{v_2}{v_1} )^n Therefore p₂ = p₁ ÷ (\frac{v_2}{v_1} )^n = (1 bar) ÷ (\frac{1}{10} )^{1.3} = 19.953 bar

Similarly for a polytropic process we have

\frac{T_1}{T_2}  = (\frac{v_2}{v_1} )^{n-1} or T₂ = T₁ ÷ (\frac{v_2}{v_1} )^{n-1} = \frac{310}{0.1^{0.3}} = 618.531 K

The molar mass of air is 28.9628 g/mol.

Therefore R = \frac{8.3145}{28.9628} = 0.287 kJ/kg⋅K

cp = 1.005 kJ/kg⋅K Therefore cv = cp - R =  1.005- 0.287 = 0.718 kJ/kg⋅K

1). For process 1 to 2 which is polytropic process we have

W = \frac{R(T_2-T_1)}{n-1} = \frac{0.287(618.531-310)}{1.3 - 1}= 295.16 kJ/kg

Q =(\frac{n-\gamma}{\gamma - 1} )W = (\frac{1.3-1.4}{1.4-1} ) 295.16 kJ/kg = -73.79 kJ/kg

W = 295.16 kJ/kg

Q = -73.79 kJ/kg

2). For process 2 to 3 which is reversible constant volume heating we have

W = 0 and Q = cv×(T₃ - T₂) = 0.718× (2200-618.531) = 1135.376 kJ/kg

W = 0

Q = 1135.376 kJ/kg

3). For process 3 to 4 which is polytropic process we have

W = \frac{R(T_4-T_3)}{n-1} = Where T₄ is given by  \frac{T_4}{T_3}  = (\frac{v_3}{v_4} )^{n-1} or T₄ = T₃ ×0.1^{0.3}

= 2200 ×0.1^{0.3}  T₄ = 1102.611 K

W =  \frac{0.287(1102.611-2200)}{1.3 - 1}= -1049.835 kJ/kg

and Q = 262.459 kJ/kg

W = -1049.835 kJ/kg

Q = 262.459 kJ/kg

4). For process 4 to 1 which is reversible constant volume cooling we have

W = 0 and Q = cv×(T₁ - T₄) = 0.718×(310 - 1102.611) = -569.09 kJ/kg

W=0

Q = -569.09 kJ/kg

(b) The thermal efficiency is given by

\eta = 1-\frac{T_4-T_1}{T_3-T_2} =1-\frac{1102.611-310}{2200-618.531} = 0.499 or 49.9 % Efficient

(c) The mean effective pressure is given by

p_{m}  = \frac{p_1r[(r^{n-1}-1)(r_p-1)]}{ (n-1)(r-1)}  where r = compression ratio and r_p = \frac{p_3}{p_2}

However p₃ = \frac{p_2T_3}{T_2} =\frac{(19.953)(2200)}{618.531} =70.97 atm

r_p = \frac{p_3}{p_2} = \frac{70.97}{19.953}  = 3.56

Therefore p_m =\frac{1*10*[(10^{0.3}-1)(3.56-1)]}{0.3*9} = 9.44 bar

Please find attached generalized diagrams of the Otto cycle

8 0
3 years ago
In software engineering how do you apply design for change?
Pavlova-9 [17]

Answer:

it is reducely very iloretable chance for a software engineer to give an end to this question

7 0
3 years ago
What is a radio wave made up of? Molecules? Electrons? Other?
mafiozo [28]

Radio waves are radiated by charged particles when they are accelerated. They are produced artificially by time-varying electric currents, consisting of electrons flowing back and forth in a specially-shaped metal conductor called an antenna. ... Radio waves are received by another antenna attached to a radio receiver.

4 0
3 years ago
Read 2 more answers
Other questions:
  • The mechanical properties of a metal may be improved by incorporating fine particles of its oxide. Given that the moduli of elas
    11·1 answer
  • A spherical, stainless steel (k 16 W m1 K-1) tank has a wall thickness of 0.2 cm and an inside diameter of 10 cm. The inside sur
    12·1 answer
  • A Carnot engine has a piston displacement volume of 7.5 liters. The volume at the beginning of heat addition is 1.0 liters, the
    14·1 answer
  • In an experiment, the local heat transfer over a flat plate were correlated in the form of local Nusselt number as expressed by
    5·1 answer
  • Air at 300 K and 100 kPa steadily flows into a hair dryer having electrical work input of 1500 W. Because of the size of the air
    6·2 answers
  • How long does it take electrons to get from a car battery to the starting motor? Assume the current is 300 A and the electrons t
    10·1 answer
  • When does someone's work on the Internet become copyrighted?
    15·1 answer
  • Limestone scrubbing is used to remove SO2 in a flue gas desulfurization (FGD) system. Relevant reactions are given below. A lime
    8·1 answer
  • At what distance from the Earth’s surface is a 10,000 kg satellite if its potential energy is equal to –5.58 x 1011 J? (choose t
    5·1 answer
  • An ideal gas is contained in a closed assembly with an initial pressure and temperature of
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!