Write a program with a loop that lets the user enter a series of positive integers. The user should enter -99 to signal the end of the series. Any negative number other than -99 must be rejected with a message “ERROR: no negative values other than -99 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 -99 right away) a message “No numbers were entered” must appear. Test cases User input (1 number):  -99  Produces output “No numbers were entered” Input 2 numbers: 1 , -99 Output: the largest number: 1 ; the smallest number: 1 Input 5 numbers :1 , 2 ,55, 0, -99 Output: the largest number: 55 ; the smallest number: 0

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

Write a program with a loop that lets the user enter a series of positive integers. The user should enter -99 to signal the end of the series. Any negative number other than -99 must be rejected with a message “ERROR: no negative values other than -99 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 -99 right away) a message “No numbers were entered” must appear.

Test cases

  1. User input (1 number):  -99 
    • Produces output “No numbers were entered
  2. Input 2 numbers: 1 , -99
    • Output: the largest number: 1 ; the smallest number: 1
  3. Input 5 numbers :1 , 2 ,55, 0, -99
    • Output: the largest number: 55 ; the smallest number: 0

 

Write a program that generates 100 random integers in a given range and stores the integers in a file with a given name. When numbers are written into the file each integer is placed on a separate line.

Requirements

The program must:

  1. Ask user to provide a range of random integers to be generated.
    • Use exceptions mechanism to validate user input to be of correct type. If the user enters anything other than integer, the program must not crash but instead output an error message containing word “ERROR”, and ask user for input again.
      1. See InputValidation.java to get example of how to do that.
      2. Use two validation loops to make the user provide two integers.
    • Both numbers of the range provided by the user must be positive integers. If the user provides negative value, a message containing word “ERROR” must be displayed, and the user must be asked to provide an integer again.
    • Continue asking user for input until the numbers fit both requirements.
    • See sample interaction with a user below.
  2. Ask user for a file name where the numbers will be written to. If the file does not exist it must be created. If it does exist, the contents of it must be replaced with the new set of random numbers.
  3. The user may give the numbers of the range in incorrect order. Your program must not break when that happens. Make sure that lower limit is smaller than upper limit. If it is not the case – swap the numbers and continue with random number generation.
  4. Open the file with the given name, generate random numbers and write them in the file, placing each new number on a new line.
  5. Use try/catch block to handle possible IOExceptions.
  6. IMPORTANT: Your main() must not throw any exceptions.

Sample user interaction - all input is correct

Enter the minimum value as a positive integer: 1
Enter the maximum value as a positive integer: 5
Enter the filename to write into: abc.txt
Data written to the file.

Sample user interaction - incorrect input handled

Enter the minimum value as a positive integer: gdfgfd
Input ERROR. Number entered was not an integer.
Enter the minimum value as a positive integer: -5
Input ERROR. Number entered was not positive.

Enter the minimum value as a positive integer: 8
Enter the maximum value as a positive integer: ewfw
Input ERROR. Number entered was not an integer.

Enter the maximum value as a positive integer: 9.7
Input ERROR. Number entered was not an integer.

Enter the maximum value as a positive integer: 3
Enter the filename to write into: someFile.txt
Data written to the file.

Expert Solution
Step 1

There are two programs and they are not interlinked. So as per our guidelines we only answer the first one.

 

  • The program will take positive integer from user.
  • First program will ask the user to input number of element they want in an array.
  • Then system will ask input element for the array.
  • If the user input value -99 then the system will popup message saying “No input number”.
  • The system will find the minimum and maximum number from the array.

 

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Basics of loop
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
  • SEE MORE 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