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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started