You have been provided with 5 .txt files named: integers1.txt, integers2.txt, integers3.txt, integers4.txt, and integers5.txt. Each file contains a list of positive integers on separate lines. Create a Java class named SortedIntegerFile that has the main method and does the following: ● Reads in the integers and determines if they are sorted in increasing order (i.e. smallest to largest). • If all of the integers are in increasing order, the program should print out: "File is sorted."

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Hi I need help with writing this program in java.

You have been provided with 5 .txt files named: integers1.txt, integers2.txt,
integers3.txt, integers4.txt, and integers5.txt.
Each file contains a list of positive integers on separate lines. Create a Java class named
SortedIntegerFile that has the main method and does the following:
●
●
●
Reads in the integers and determines if they are sorted in increasing order (i.e. smallest to
largest).
If all of the integers are in increasing order, the program should print out: "File is
sorted."
If the file is not sorted, throw an Exception with the message: "File not sorted", then
handle the exception by displaying the result of calling the getMessage method and printing
out the first two integers that are not sorted.
If a line in the file is not valid input (i.e. less than 0 or not an integer), handle an
InputMismatchException and print out "File contains values other than
positive integers." Note that the nextInt method will throw this exception for you if
the value is other than an int, but it will not throw it if the value is a negative integer.
If no file can be found, handle the exception and print out "File not found.".
See below for the output for each file.
Transcribed Image Text:You have been provided with 5 .txt files named: integers1.txt, integers2.txt, integers3.txt, integers4.txt, and integers5.txt. Each file contains a list of positive integers on separate lines. Create a Java class named SortedIntegerFile that has the main method and does the following: ● ● ● Reads in the integers and determines if they are sorted in increasing order (i.e. smallest to largest). If all of the integers are in increasing order, the program should print out: "File is sorted." If the file is not sorted, throw an Exception with the message: "File not sorted", then handle the exception by displaying the result of calling the getMessage method and printing out the first two integers that are not sorted. If a line in the file is not valid input (i.e. less than 0 or not an integer), handle an InputMismatchException and print out "File contains values other than positive integers." Note that the nextInt method will throw this exception for you if the value is other than an int, but it will not throw it if the value is a negative integer. If no file can be found, handle the exception and print out "File not found.". See below for the output for each file.
For file: integers1.txt
File is sorted.
For file: integers4.txt
File is sorted.
For file: integers2.txt
File not sorted.
634 occurs before 706
For file: integers5.txt
File contains values other
than positive integers.
For file: integers3.txt
File contains values other
than positive integers
For file: integers6.txt
File not found.
Transcribed Image Text:For file: integers1.txt File is sorted. For file: integers4.txt File is sorted. For file: integers2.txt File not sorted. 634 occurs before 706 For file: integers5.txt File contains values other than positive integers. For file: integers3.txt File contains values other than positive integers For file: integers6.txt File not found.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY