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
Aviation ppl onlyyyy ayoooo, thoughts on the A-10 Thunderbolt II?
Vaselesa [24]

Answer:

It’s cool I’d say 8/10 I guess

Explanation:

8 0
3 years ago
A particular cloud-to-ground lightning strike lasts 500 µµsec and delivers 30 kA across a potential difference of 100 MV. Assu
sasho [114]

Answer:

a) 15 C charge was delivered by the lightening bolt

b) the lightning delivered 3.0 × 10¹² W of power

c)

- total energy delivered by the lightening strike in J is 1500 × 10⁶ J

- total energy delivered by the lightening strike in Wh is 416666.67 Wh

d)

the residential retail value of the energy delivered by the strike is $ 40.83

e)

a total of 26 lightening strikes would be required to power an average US home for a year.

Explanation:

Given that;

the lighting strike lasted for t ( time ) = 500 μsecs = 500×10⁻⁶ s

Current I = 30 kA = 30×10³ A

voltage V = 100 mV = 100×10⁶ v

a)

we know that; I = Q/t

so Q = I × t

we substitute

Q =  30×10³ × 500×10⁻⁶

Q = 15 C

Therefore 15 C charge was delivered by the lightening bolt

b)

Power P = V × I

we substitute

Power P = 100×10⁶ × 30×10³

P = 3.0 × 10¹² W

Therefore, the lightning delivered 3.0 × 10¹² W of power

c)

we know that; Power = Energy / Time

Energy = Power × Time

we substitute

E = 3.0 × 10¹²  × 500×10⁻⁶

E = 1500 × 10⁶ J

- total energy delivered by the lightening strike in J is 1500 × 10⁶ J

- total energy delivered by the lightening strike in Wh is;

⇒ 1500×10⁶ / 3600 Wh

= 416666.67 Wh

d)

given that;  1 KWh → $ 0.098

energy delivered by the strike = 416666.67 Wh = 416.66667 KWh

so the residential retail value of the energy delivered by the strike will be;

416.66667 KWh × $ 0.098

= $ 40.83

∴ the residential retail value of the energy delivered by the strike is $ 40.83

e)

Given that; average monthly residential energy consumption is 900 kWh.

for a year; energy consumption = 12 × 900 kWh = 10,800 KWh = 10800000 Wh

Now

1 lightening strike ⇒ 416666.67 Wh

x lightening strike ⇒ 10800000 Wh

x = 10800000 / 416666.67

x = 25.9199 ≈ 26

Therefore; a total of 26 lightening strikes would be required to power an average US home for a year.  

7 0
3 years ago
What is the purpose of an engineer?
amid [387]

Answer:

Their purpose is to invent, design, analyze, build and test machines, complex systems, structures, gadgets and materials to fulfill functional objectives and requirements while considering the limitations imposed by practicality, regulation, safety and cost.

4 0
3 years ago
Read 2 more answers
Explain with schematics the operating principle of solid state lasers.
alina1380 [7]

Explanation:

A solid state laser contains a cavity like structure fitted with spherical mirrors or plane mirrors at the end filled with a rigidly bonded crystal. It uses solid as the medium. It uses glass or crystalline materials.

    It is known that active medium used for this type of laser is a solid material. This lasers are pumped optically by means of a light source which is used as a source of energy for the laser. The solid materials gets excited by absorbing energy in the form of light from the light source. Here the pumping source is light energy.  

7 0
3 years ago
Document the XSS stored exploit script: Use the View Source feature of the web page and create a screenshot of the few lines cod
Natali [406]

Answer:

Hold on let me ask my brother

Explanation:

5 0
3 years ago
Other questions:
  • A steel ship deck plate is 30 mm thick and 12 m wide. It is loaded with a nominal uni- axial tensile stress of 70 MPa. It is ope
    13·1 answer
  • A metal plate of 400 mm in length, 200mm in width and 30 mm in depth is to be machined by orthogonal cutting using a tool of wid
    12·2 answers
  • Which is/are not a mechanism commonly associated with tool wear (mark all that apply)?a. Adhesion b. Attrition c. Abrasion d. Co
    10·1 answer
  • Cavitation in pump assemblies can be avoided by decreasing tank pressure. a)-True b)-False
    10·1 answer
  • ____________________________________________ help scientists understand processes in the natural world by providing simpler repr
    11·2 answers
  • Is there anyone who can help me with welding?
    12·1 answer
  • Define the word vision statement​
    5·1 answer
  • Some wire of radius is 1.262mm has a resistance of 20Ω. Determine the resistance of a wire of the same length and material if th
    14·2 answers
  • What precautions should be taken to avoid the overloading of domestic electric circuits.
    13·1 answer
  • What are the reasons why fine grained of alkali igneous rocks can not be used in cement
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!