Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following is pseudocode for validation of an integer value. Initialize valid flag, input value While not valid Prompt for an integer While the next

The following is pseudocode for validation of an integer value.

Initialize valid flag, input value

While not valid

Prompt for an integer

While the next word is NOT an integer

Fetch the next word (do not use it)

Write Error message

End While

Fetch the integer

If it is in range, set valid flag to true, else display error message

End While

Print the input value

You will create a project called AverageTestScore with a class called AverageTestScore. In your main() method, create a loop that prompts for test scores and validates the values entered. Use a sentinel value (-1) to end the input. Then print the average test score and number of tests. Use printf to round the average to 1 decimal place.

Example storyboards:

//Normal flow

AverageTestScore by Joe Student

Enter Test Scores below, use -1 to end

Enter Test Score: 100

Enter Test Score: 90

Enter Test Score: 85

Enter Test Score: -1

Average score = 91.7 Number of tests = 3

//Catch non-integers

AverageTestScore by Joe Student

Enter Test Scores below, use -1 to end

Enter Test Score: 100

Enter Test Score: eighty

Please enter an integer

80

Enter Test Score: -1

Average score = 90.0

Number of tests = 2

//Catch No Data

AverageTestScore by Joe Student

Enter Test Scores below, use -1 to end

Enter Test Score: -1

No Data.

//Catch non-integers (doubles) and value out of range

AverageTestScore by Joe Student

Enter Test Scores below, use -1 to end

Enter Test Score: 100.5

Please enter an integer

101

Test scores must be between 0 and 100

Enter Test Score: 100

Enter Test Score: -1

Average score = 100.0 Number of tests = 1

Hints: You may find it useful to look at the textbook 4.7.1 and construct your loops as follows:

boolean done = false;

while (!done)

{

boolean valid = false;

while (!valid)

{

Also, you can use in.next() to fetch the next word as a string, e.g. when its not an integer.image text in transcribed

while not done prompt for test score (get valid int) while (not valid) what is range of valid values? test for sentient value sum sum + score

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions