Question: Objectives To perform while (or do-while) loops. To integrate conditionals into while loops. To translate a simple flowchart into a program. Prerequisites Do this problem

Objectives

To perform while (or do-while) loops.

To integrate conditionals into while loops.

To translate a simple flowchart into a program.

Prerequisites

Do this problem after you have completed the previous iteration problems.

Description

Write a program (aboveThreshold.scala) that reads in a value (integer) N, a threshold (double) T, and a list of N (double) numbers and then outputs the amount of numbers that were above the threshold. (Observe that "equal to" is NOT "above.")

Sample Run

The following is a sample run. It includes both input and output. For clarity, the input lines are preceded by the symbol > and the shell command (to start the program) is preceded by the symbol $. A sample input and output are separated afterwards.

How many numbers should I read? > 5 What is the threshold? > 2.5 Please enter 5 numbers. > 1.2 > 3.2 > -2.8 > 2.5 > 5.6 There were 2 values above the threshold. 

Input

Here is just a sample input to the program.

5 2.5 1.2 3.2 -2.8 2.5 5.6 

Output

Here is just a sample output to the program. Notice that the prompts are part of the program's output.

How many numbers should I read? What is the threshold? Please enter 5 numbers. There were 2 values above the threshold. 

Hint

For this program, you should translate the attached solution (aboveThreshold.png) presented as a flowchart into Scala. Note that this will require you to have an if-statement inside a while loop.

https://s3.amazonaws.com/mimirplatform.production/projects/badd0144-3f7a-4dc4-86c0-e9e4b21744f3/description_files/aboveThreshold.png

Need in scala

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!