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
We are given a CSP with only binary constraints. Assume we run backtracking search with arc consistency as follows. Initially, w
sweet-ann [11.9K]
We are given a CSP with only binary can concentrate assume we run backtrackingSearch with ARC
8 0
2 years ago
Stream Piracy – Kaaterskill, NY. Check and double-click the Problem 15 folder. The dark blue and orange streams highlight the pr
baherus [9]

Answer:

b. The pirating streams are eroding headwardly to intersect more of the other streams’ drainage basins, causing water to be diverted down their steeper gradients.

Explanation:

From the Kaaterskill NY 15 minute map (1906), this shows two classic examples of stream capture.

The Kaaterskill Creek flow down the east relatively steep slopes into the Hudson River Valley. While, the Gooseberry Creek is a low gradient stream flowing down the west direction which in turn drains the higher parts of the Catskills in this area.

However, there is Headward erosion of Kaaterskill Creek which resulted to the capture of part of the headwaters of Gooseberry Creek.

The evidence for this is the presence of "barbed" (enters at obtuse rather than acute angle) tributary which enters Kaaterskill Creek from South Lake which was once a part of the Gooseberry Creek drainage system.

It should be noted again, that there is drainage divide between the Gooseberry and Kaaterskill drainage systems (just to the left of the word Twilight) which is located in the center of the valley.

As it progresses, this divide will then move westward as Kaaterskill captures more and more of the Gooseberry system.

5 0
3 years ago
A program is seeded with 30 faults. During testing, 21 faults are detected, 15 of which are seeded faults and 6 of which are ind
Vesna [10]

Answer:

Estimated number of indigenous faults remaining undetected is 6

Explanation:

The maximum likelihood estimate of indigenous faults is given by,

N_F=n_F\times \frac{N_S}{n_S} here,

n_F = the number of unseeded faults = 6

N_S = number of seeded faults = 30

n_s = number of seeded faults found = 15

So NF will be calculated as,

N_F=6\times \frac{30}{15}=12

And the estimate of faults remaining is  N_F-n_F = 12 - 6 = 6

8 0
3 years ago
A piston-cylinder device contains 0.58 kg of steam at 300°C and 0.5 MPa. Steam is cooled at constant pressure until one-half of
Mumz [18]

Answer:

a) Tբ = 151.8°C

b) ΔV = - 0.194 m³

c) The T-V diagram is sketched in the image attached.

Explanation:

Using steam tables,

At the given pressure of 0.5 MPa, the saturation temperature is the final temperature.

Right from the steam tables (A-5) with a little interpolation, Tբ = 151.793°C

b) The volume change

Using data from A-5 and A-6 of the steam tables,

The volume change will be calculated from the mass (0.58 kg), the initial specific volume (αᵢ) and the final specific volume

(αբ) (which is calculated from the final quality and the consituents of the specific volumes).

ΔV = m(αբ - αᵢ)

αբ = αₗ + q(αₗᵥ) = αₗ + q (αᵥ - αₗ)

q = 0.5, αₗ = 0.00109 m³/kg, αᵥ = 0.3748 m³/kg

αբ = 0.00109 + 0.5(0.3748 - 0.00109)

αբ = 0.187945 m³/kg

αᵢ = 0.5226 m³/kg

ΔV = 0.58 (0.187945 - 0.5226) = - 0.194 m³

c) The T-V diagram is sketched in the image attached

3 0
3 years ago
The Role of Fuel Cells in Renewable Energy Solutions
gogolik [260]

Answer:

chemical energy directly

4 0
2 years ago
Other questions:
  • A circuit-switching scenario in whichNcs users, each requiring a bandwidth of 25 Mbps, must share a link of capacity 150 Mbps.
    12·1 answer
  • Are all transmissions fluids interchangeable
    5·1 answer
  • The Emergency Stop Button icon on the Inputs toolbar can be used to press or release the Emergency Stop button on the CNC machin
    10·1 answer
  • A steel wire of diameter 2.000 mm and length 1.000 m is attached between two immovable supports.When the temperature is 60.00 Ce
    9·1 answer
  • A water tower that is 90 ft high provides water to a residential subdivision. The water main from the tower to the subdivision i
    10·1 answer
  • Output all combinations of character variables a, b, and c. If a = 'x', b = 'y', and c = 'z', then the output is: xyz xzy yxz yz
    14·1 answer
  • When -iron is subjected to an atmosphere of hydrogen gas, the concentration of hydrogen in the iron, CH (in weight percent), is
    5·1 answer
  • When we say that communication is
    13·1 answer
  • Which word from the passage best explains what the web in the passage symbolizes
    10·1 answer
  • Characteristics of 3 types of soil​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!