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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 10:20, vuqepete4528
Shown below is the start of a coding region within the fist exon of a gene. 5'--3' 3'--5' how many cas9 pam sequences are present?
Answers: 1
image
Computers and Technology, 22.06.2019 10:40, Morghurley2000
"it security policy enforcement and monitoring" respond to the following: describe how monitoring worker activities can increase the security within organizations. describe the rationale that managers should use to determine the degree of monitoring that the organization should conduct. explain the extent to which you believe an organization has the right to monitor user actions and traffic. determine the actions organizations can take to mitigate the potential issues associated with monitoring user actions and traffic.
Answers: 3
image
Computers and Technology, 22.06.2019 11:10, lberman2005p77lfi
The total cost of textbooks for the term was collected from 36 students. create a histogram for this data. $140 $160 $160 $165 $180 $220 $235 $240 $250 $260 $280 $285 $285 $285 $290 $300 $300 $305 $310 $310 $315 $315 $320 $320 $330 $340 $345 $350 $355 $360 $360 $380 $395 $420 $460 $460
Answers: 2
image
Computers and Technology, 22.06.2019 15:20, brookemcelhaney
The north and south regions had very diferent economies in the 1800s.
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 in other subjects:

Konu
History, 16.07.2019 18:00