subject
Computers and Technology, 10.05.2021 18:10 fatty18

The project downloaded contains a package (folder) named Q1 within the src folder. Inside Q1 is a Java class named Questions. The purpose of Question 1 is to examine your understanding of loops and branching conditions. You should implement all of your code for this question in the main method of the Questioni class. While significant detail is provided below to be sure you undertand what is required, please note that the amount of code required to solve this question (Parts a-c) is less than 10 lines (total). In the Question1 class, you are given a line of code that generates a random number between 0 and 1. Math. random(): //generates number between 0 and 1 val You are to create a loop which, in each iteration, generates a new random value, assigns it to val using the line provided and checks to see if that val is greater than 0.5. If val is greater than 0.5, a variable named counter should be incremented. The loop should continue this process (generate random value, check if it is greater than 0.5) until a total of three random numbers generated are greater than 0.5 (values do not have to be consecutive). You should also use the variable named numIterations, which is included for you, to track how many iterations of your loop were required for you to generate three random numbers greater than 0.5. A printin() statement is included for you that displays the value of numlterations. As an example of how the program should behave, if the following sequence of random numbers are randomly generated from your loop
0.3, 0.7,0.2, 0.6,0.9
then numIterations would equal 5 (the third value greater than 0.5 occured on the fifth iteration).
If
0.6, 0.8, 0.75
was the random sequence of numbers generated by your loop, then numlterations would equal 3 (the third value greater than 0.5 occured on the third iteration).
These are two examples to illustrate the scenario given in Question 1. Since at each iteration of your loop the number generated is random, the value of numIterations that your program observes may be any value greater than or equal to 3. Note that your program does not need to print out each of the random values that it generates. The steps to solve Question 2 are broken down as follows.
a. Implement a branching condition that increases the variable counter by 1 if val is larger than 0.5 1
b. Add a loop around the code created in Part a that continues until counter equals 3.
c. Use the variable numlterations to count how many times your loop iterates.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 09:00
Create a cell reference in a formula by typing in the cell name or         a. right-clicking the cell. b. clicking the cell. c. clicking the column where the cell is located. d. clicking the row where the cell is located.
Answers: 1
question
Computers and Technology, 22.06.2019 17:00
Your company has 1,500 desktop computers running windows 7. you want to upgrade them to windows 10. which type of microsoft license would be best suited in this situation?
Answers: 3
question
Computers and Technology, 22.06.2019 19:20
How might the success of your campaign be affected if you haven’t carefully completed all field data or if you accidentally insert the wrong merge field in the document?
Answers: 2
question
Computers and Technology, 22.06.2019 20:00
What is the term for water wave that is created by an underwater earthquake
Answers: 1
You know the right answer?
The project downloaded contains a package (folder) named Q1 within the src folder. Inside Q1 is a Ja...
Questions
question
Mathematics, 18.12.2020 09:00
question
Mathematics, 18.12.2020 09:00
question
Mathematics, 18.12.2020 09:00
question
Biology, 18.12.2020 09:00
question
Mathematics, 18.12.2020 09:00
question
Mathematics, 18.12.2020 09:00
question
Mathematics, 18.12.2020 09:00
Questions on the website: 13722359