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
Which of the following Identifies the challenges faced by scientists experimenting with using artificial photosynthesis as
bezimeni [28]

Answer:

The cost and size of materials needed to produce energy

Explanation:

Artificial photosynthesis is a chemical process that uses solar cells instead of chlorophyll to absorb sunlight and convert it into electricity. This process uses artificial leaves that require man-made catalyst to spilt water present in the air into hydrogen and oxygen. It is clear that the reaction requires heat from the sun for energy production thus the technology is expensive to be applied in most areas of the world. Additionally, results obtained from previous undertaken projects of this type has been ineffective and unsustainable because it involves a lot of trial and error.

8 0
3 years ago
A task is something that you can physically do.
Jet001 [13]
The answer is T because a task is getting something done
5 0
3 years ago
Read 2 more answers
How do we find percentage error in measuring voltage across a resistor​
Black_prince [1.1K]

Answer:

  use the percentage error relation

Explanation:

The percentage error in anything is computed from ...

  %error = ((measured value)/(accurate value) -1) × 100%

__

The difficulty with voltage measurements is that the "accurate value" may be hard to determine. It can be computed from the nominal values of circuit components, but there is no guarantee that the components actually have those values.

Likewise, the measuring device may have errors. It may or may not be calibrated against some standard, but even measurement standards have some range of possible error.

6 0
3 years ago
Read 2 more answers
(1) Prompt the user for the number of cups of lemon juice, water, and agave nectar needed to make lemonade. Prompt the user to s
Lady bird [3.3K]

Answer:

The program to this question as follows:

Program:

Lemon= float(input('Enter lemon juice value in cups: ')) #defining float variable and input value by user

Water= float(input('Enter water value in cups: ')) #defining float variable and input value by user

Agave= float(input('Enter agave nectar value in cups: ')) #defining float variable and input value by user

Serve= float(input('enter serving value: '))  #defining float variable and input value by user

print ('Lemonade ingredients - yields',Serve,'servings',) #print value

print (Lemon,'cups in lemon juice',) #print value

print (Water,'cups in water',) #print value

print (Agave,'cups in agave nectar',) #print value

Output:

Enter lemon juice value in cups: 2

Enter water value in cups: 3

Enter agave nectar value in cups: 2

enter serving value: 2

Lemonade ingredients - yields 2.0 servings

2.0 cups in lemon juice

3.0 cups in water

2.0 cups in agave nectar

Explanation:

In the above python code, four float variable "Lemon, Water, Agave, and Serve" is defined, which is the input function is used.  

  • The input function message is written that passes in function parameter, that accepts value in the above variables.  
  • In the next step, the print function is used, which prints the above user input values.
6 0
4 years ago
A vertical plate is partially submerged in water and has the indicated shape. The height is 3m, the width at the top is 4m, and
natka813 [3]

Answer: 1.98 × 10^4 N

Explanation:

Form similar triangle ADE and ABC

a/x= 2/3, a=2/3x

Width of the strip w= 2(4+a) = 8+2a

W= 8 +2 (2/3x)= 8+4/3x

Area of the strip = w Δx

(8 +4/3x) Δx

Pressure on the strip p= pgx= 10^3 ×9.81x= 9810x

But,

Force= Pressure × area= 9810x × (8+4/3x)Δx

Adding the forces and taking lim n to infinity

F total= lim n--> infinity E 9810x × (8+4/3x)Δx

Ftotal= Integral 2,0 9810x × (8+4/3x)Δx

F total= 9810 integral 2, 0 (8+4/3x)dx

= 9810(8+x^2/2 + 4/3x^3/3)2,0

=9810(4x^2 + 4/9x^3)

=9810(4x2^2 + 4/9×2^3-0)

=9810(16 + 32/9)

Hydrostatic force as an integral

Ft= 19.18 ×10^4N

7 0
3 years ago
Other questions:
  • Six housing subdivisions within a city area are target for emergency service by a centralized fire station. Where should the new
    5·1 answer
  • Find the difference between the first and third angle projection type.
    11·1 answer
  • In a four bar mechanism, L, is a fixed link; L2 is driver crank; L3 is coupler and L4 is follower crank. L=27 cm, L3 =5 cm and L
    5·1 answer
  • A hypothetical metal alloy has a grain diameter of 2.4 × 10−2 mm. After a heat treatment at 575°C for 500 min, the grain diamete
    12·1 answer
  • which systems engineering support discipline has the goal to ensure that support considerations are an integral part of the syst
    14·1 answer
  • Please help been stuck on this for a couple minutes
    5·1 answer
  • Which type of engineers were the designers of the Great Pyramids of Egypt and the Great Wall of China?
    9·2 answers
  • A step-up transformer has 20 primary turns and 400 secondary turns. If the primary current is 30 A, what is the secondary curren
    15·1 answer
  • What type of social engineering targets particular?.
    11·1 answer
  • Your class is using engineering principles to improve the design of football helmets to prevent brain injury. your teacher divid
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!