Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The Greatest and the Least of These Write a program with a loop that lets the user enter a series of positive integers. The user
The Greatest and the Least of These
Write a program with a loop that lets the user enter a series of positive integers. The user should enter to signal the end of the series. Any negative number other than must be rejected with a message ERROR: no negative values other than accepted! After all the numbers have been entered, the program should display the largest and the smallest numbers entered. If no numbers were entered user entered right away a message No numbers were entered must appear.
Name your solution project GreatestAndLeast.java.
Use The greatest of a set of numbers algorithm see below to solve the problem.
Requirements:
Your code must run correctly on the test cases provided below.
DO NOT use arrays or ArrayLists to store the numbers in the series. Numbers must be analyzed on the spot and discarded
Error message in response to negative value other than must include word ERROR to pass the CodeGrade tests.
No numbers were entered must appear when no numbers were entered.
When user entered at least one integer other than the report must list first the largest number, with the word largest preceding it and then the smallest number, with the word smallest preceding it See sample user interaction for more details. These details are important to pass the CodeGrade tests.
The greatest of a set of numbers algorithm:
Get input the first number, set it to be the greatest one for now.
Get the next number.
If the new number is bigger than the greatest one set the new one to be the greatest
Repeat steps until all the numbers are consumed.
Test cases
User input number:
Produces output No numbers were entered
Input numbers:
Output: the largest number: ; the smallest number:
Input numbers :
Output: the largest number: ; the smallest number:
Name your solution project GreatestAndLeast.java.
User interaction sample #
Enter a positive integer number. Enter to stop input.
No numbers were entered
User interaction sample #
Enter a positive integer number. Enter to stop input.
Enter a positive integer number. Enter to stop input.
Enter a positive integer number. Enter to stop input.
ERROR: negative integers other than are not allowed.
Enter a positive integer number. Enter to stop input.
Enter a positive integer number. Enter to stop input.
the largest number: ; the smallest number:
User interaction sample #
Enter a positive integer number. Enter to stop input.
Enter a positive integer number. Enter to stop input.
ERROR: negative integers other than are not allowed.
Enter a positive integer number. Enter to stop input.
the largest number: ; the smallest number:
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