If your code is missing any of the components below, you will not get any credit. Please read the instructions carefully. Write a program that asks the user to input 5 positive integers. Use a for loop that loops 5 times for this. Have your program throw exceptions if any given values are negative (throw a custom exception). Also, be sure to protect against non-integer inputs (input mismatches). If the user fails on any of the five inputs they will need to input that one again. After 5 successful positive integer inputs report the sum of the five numbers to the screen as well as the average of those five numbers to the screen. The average should be the actual average (a double, not an int). You MUST use a for loop to obtain all 5 values. Do not just write the same code out 5 times. (This is different than program 1!) You MUST total and average the 5 values. You’ll need to find a way to manipulate the for loop in the event the user enters an invalid input, because an invalid input will still cause you to use up one of your iterations in the loop. Make sure the user is forced to correct their bad input immediately after they enter it. If you have them re-type in all 5 numbers each time they have an invalid input, this is not what I want. Also, include in your output which number they are on, as shown below. Tip: Create the for loop first, then put the try/catch structure inside. You will need two catch blocks. The example below is the exact set of test values I will use to test your program but your program should be able to handle ANY input.

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. If your code is missing any of the components below, you will not get any credit. Please read the instructions carefully.

  2. Write a program that asks the user to input 5 positive integers. Use a for loop that loops 5 times for this.

  3. Have your program throw exceptions if any given values are negative (throw a custom exception). Also, be sure to protect against non-integer inputs (input mismatches).

  4. If the user fails on any of the five inputs they will need to input that one again.

  5. After 5 successful positive integer inputs report the sum of the five numbers to the screen as well as the average of those five numbers to the screen. The average should be the actual average (a double, not an int).

  6. You MUST use a for loop to obtain all 5 values. Do not just write the same code out 5 times. (This is different than program 1!) You MUST total and average the 5 values. You’ll need to find a way to manipulate the for loop in the event the user enters an invalid input, because an invalid input will still cause you to use up one of your iterations in the loop.

  7. Make sure the user is forced to correct their bad input immediately after they enter it. If you have them re-type in all 5 numbers each time they have an invalid input, this is not what I want. Also, include in your output which number they are on, as shown below.

  8. Tip: Create the for loop first, then put the try/catch structure inside. You will need two catch blocks.

  9. The example below is the exact set of test values I will use to test your program but your program should be able to handle ANY input.

 

Example:

 

This program will give the sum & average of 5 positive integer.

Please enter number 1:

>>>5

Please enter number 2:

>>>hi

Wrong data type.

Please enter number 2: //asks for number 2 again

>>>4

Please enter number 3:

>>>3

Please enter number 4:

>>>2.5

Wrong data type.

Please enter number 4: //asks for number 4 again

>>>2

Please enter number 5:

>>>-1

Value must be positive. //asks for number 5 again

Please enter number 5:

>>>1

 

The sum is 15 and the average of your 5 numbers is 3.0.

 

in 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