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
What are the most used electronic tools for electronic works?​
Zanzabum

Answer:

  • Needle-nose pliers.
  • Hemostats.
  • A spool of 30-gauge wire.
  • A spool of solder wick.
  • A spool of solder.
  • A loupe.
  • Three sets of tweezer

6 0
3 years ago
Refrigerant-134a enters the expansion valve of a refrigeration system at 120 psia as a saturated liquid and leaves at 20 psia. D
Shkiper50 [21]

Solution :

$P_1 = 120 \ psia$

$P_2 = 20 \ psia$

Using the data table for refrigerant-134a at P = 120 psia

$h_1=h_f=40.8365 \ Btu/lbm$

$u_1=u_f=40.5485 \ Btu/lbm$

$T_{sat}=87.745^\circ  F$

∴ $h_2=h_1=40.8365 \ Btu/lbm$

For pressure, P = 20 psia

$h_{2f} = 11.445 \ Btu/lbm$

$h_{2g} = 102.73 \ Btu/lbm$

$u_{2f} = 11.401 \ Btu/lbm$

$u_{2g} = 94.3 \ Btu/lbm$

$T_2=T_{sat}=-2.43^\circ  F$

Change in temperature, $\Delta T = T_2-T_1$

                                         $\Delta T = -2.43-87.745$

                                           $\Delta T=-90.175^\circ  F$

Now we find the quality,

$h_2=h_f+x_2(h_g-h_f)$

$40.8365=11.445+x_2(91.282)$

$x_2=0.32198$

The final energy,

$u_2=u_f+x_2.u_{fg}$

   $=11.401+0.32198(82.898)$

   $=38.09297 \ Btu/lbm$

Change in internal energy  

$\Delta u= u_2-u_1$

   = 38.09297-40.5485

  = -2.4556        

5 0
3 years ago
5. A typical paper clip weighs 0.59 g and consists of BCC iron. Calculate (a) the number of
marta [7]

Answer:

(a) 3.185*10^{21} cells

(b) 6.37*10^{21} atoms

Explanation:

(a)

Volume, V of unit cell

V=(2.866*10^{-8})^{3}=2.354*10^{-23}

Number of unit cells, N

N=\frac {W_{mat}}{V\rho_{mat}} Where W_{mat} is weight of material and \rho_{mat} is density of material

N=\frac{0.59}{7.87*(2.354*10^{-23}}=3.185*10^{21} cells

(b)

Number of atoms in paper clip

This is a product of number of unit cells and number of atoms per cell

Since iron has 2 atoms per cell

Number of atoms of iron=3.185*10^{21} cells*2 atoms/cell=6.37*10^{21} atoms

8 0
3 years ago
How much work, in Newtons, is required to lift a 20.4-kg (45lb) plate from the ground to a stand that is 1.50 meters up?
nataly862011 [7]

Answer:

Explanation:

Work, U, is equal to the force times the distance:

U = F · r

Force needed to lift the weight, is equal to the weight: F = W = m · g

so:

U = m · g · r

   = 20.4kg · 9.81 \frac{N}{kg} · 1.50m

   = 35.316 \frac{N}{m}

   = 35.316 W

4 0
2 years ago
A solid circular rod that is 600 mm long and 20 mm in diameter is subjected to an axial force of P = 50 kN The elongation of the
Kay [80]

Answer:

a) V = 0.354

b)  G = 25.34 GPA

Explanation:

Solution:

We first determine Modulus of Elasticity and Modulus of rigidity

Elongation of rod ΔL = 1.4 mm

Normal stress, δ = P/A

Where P = Force acting on the cross-section

A = Area of the cross-section

Using Area, A = π/4 · d²

= π/4 · (0.0020)²  = 3.14 × 10⁻⁴m²

δ = 50/3.14 × 10⁻⁴    = 159.155 MPA

E(long) = Δl/l  = 1.4/600 = 2.33 × 10⁻³mm/mm

Modulus of Elasticity Е = δ/ε

= 159.155 × 10⁶/2.33 × 10⁻³    = 68.306 GPA

Also final diameter d(f) = 19.9837 mm

Initial diameter d(i) = 20 mm

Poisson said that V = Е(elasticity)/Е(long)

= -  <u>( 19.9837 - 20 /20)</u>

        2.33 × 10⁻³                  

= 0.354,

∴ v = 0.354

Also G = Е/2. (1+V)

=  68.306 × 10⁹/ 2.(1+ 0.354)

= 25.34 GPA

⇒ G = 25.34 GPA

5 0
4 years ago
Other questions:
  • A flocculation basin equipped with revolving paddles is 60 ft long (the direction of flow). 45 ft wide, and 14 ft deep and treat
    11·1 answer
  • Estimate the quantity of soil to be excavated from the borrow pit​
    12·1 answer
  • The pressure forces on a submersed object will be (A)- Tangential to the objects body (B)- Parallel (C)- Normal (D)- None of the
    10·1 answer
  • When wasDisney Cruise Line founded
    5·1 answer
  • What engine does chrysler 300c have?​
    15·1 answer
  • THIS IS NOT AN ACADEMIC QUESTION, but who was the bitter of 1987 in FNAF?
    6·2 answers
  • g Asbestos is a fibrous silicate mineral with remarkably high tensile strength. But is no longer used because airborne asbestos
    5·1 answer
  • 3. What is special about beryllium-copper alloy tools?
    6·2 answers
  • Raw materials used of silicone rubber
    6·2 answers
  • The driver should be able to see the ground within _____ to the front?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!