This program will add three integers that the user inputs. The first value must be between 0 and 50. The second value must be between 51 and 100. The third value must be greater than 100. Your program should use try/catch blocks and loops to protect against input mismatches and to get a value within the above ranges. You MUST use custom exceptions for the input range. I know this could also be accomplished using if/else statements, but I want you to use try/catches for this. You MUST obtain each number from the user one at a time and make sure it is acceptable before moving on. This may require the use of THREE loops, each with its own request for input and try/catch blocks. Once you have three good values, print the sum of them to the screen. You will receive no credit if you make the user input all three numbers multiple times. (See Incorrect Samples)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  1. This program will add three integers that the user inputs. The first value must be between 0 and 50. The second value must be between 51 and 100. The third value must be greater than 100.

  2. Your program should use try/catch blocks and loops to protect against input mismatches and to get a value within the above ranges.

  3. You MUST use custom exceptions for the input range. I know this could also be accomplished using if/else statements, but I want you to use try/catches for this.

  4. You MUST obtain each number from the user one at a time and make sure it is acceptable before moving on. This may require the use of THREE loops, each with its own request for input and try/catch blocks.

  5. Once you have three good values, print the sum of them to the screen.

  6. You will receive no credit if you make the user input all three numbers multiple times. (See Incorrect Samples)

 

CORRECT SAMPLE OUTPUT: (Notice how we do not move on from an input until we get something acceptable.)

 

This program will add three numbers. .

Please enter number 1 (between 0 and 50):

>>>-4

Invalid input. Number must be between 0 and 50.

Please enter number 1 (between 0 and 50:

>>>10

Please enter number 2 (between 51 and 100):

>>>nine

Must be an integer.

Please enter number 2 (between 51 and 100:

>>>60

Please enter number 3 (greater than 100):

>>>2.4

Must be an integer.

Please enter number 3 (greater than 100):

>>>200

 

The sum is 270.

Goodbye.

 

INCORRECT SAMPLE OUTPUT: (This does not tell us where the problem is and requires us to enter all three numbers in again.)

 

This program will add three numbers. The first must be between 0 and 50. The second between 51 and 100. The third greater than 101.

Please enter your three numbers:

>>>7

>>>6

>>>2.5

Invalid input.

 

Please enter three numbers:

Etc.

 

INCORRECT SAMPLE OUTPUT: (This has us enter one value at a time, but doesn’t catch the error immediately. When there’s an error, it makes us start over.)

 

This program will add three numbers. The first must be between 0 and 50. The second between 51 and 100. The third greater than 101.

Please enter number 1:

>>>1

Please enter number 2:

>>>6

Please enter number 3:

>>>2.5

Invalid Input.

Please enter number 1:

Etc…

 with JAVA

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education