CSC1850 Object and Oriented

Description

Exception Handling and Text I/O with Command-Line Arguments

Don't use plagiarized sources. Get Your Custom Assignment on
CSC1850 Object and Oriented
From as Little as $13/Page

In this assignment, you will create a Java program that reads and writes data from and to text
files while handling exceptions. The program will accept two command-line arguments: the
input text file and the output text file. It will read data from the input file, perform some
operations on the data, and then write the results to the output file. Additionally, you will
implement exception handling to handle potential errors gracefully.
Requirements:
1. The program accepts two command-line arguments: the input file and the output file. (10
points)
2. Implement exception handling to handle the following scenarios (30 points):
 If the input file specified as the first command-line argument is not found, display an
error message and terminate the program.
 If there are non-integer values (e.g., string, real numbers) in the input file, catch the
exception and display an error message for each invalid value. The program should
continue reading the next valid value.
 If the input file is empty, display a message indicating that the file is empty and terminate
the program.
3. Read the integers from the input file, calculate their sum, average, minimum, and maximum,
and store these values in variables. (20 points)
4. Create and write to the output text file specified as the second command-line argument, as
shown in the previous assignment. (20 points)
5. Use appropriate exception handling for file I/O, such as handling file not found or write
errors, and display informative error messages in case of any issues. (20 points)
Sample Usage:
To run the program, open the terminal and use the following command:
java YourProgramName input.txt output.txt
Sample Output:

If “input.txt” contains:
Hello 10 20 30
40 50 1.0
5.20 abc uncp ?
After running the program with the command provided, “output.txt” should contain:
Sum: 150
Average: 30
Minimum: 10
Maximum: 50
Hints:
 Use args[0] and args[1] to access the command-line arguments for the input and output
file names.
 Use a try-catch block to catch exceptions related to file operations.
 For reading the input file, you can use a Scanner object.
 For writing to the output file, you can use a PrintWriter object.
 Use the hasNextInt() method to check if the next token is an integer before reading it.
Submission:
Describe how to run your program, and screenshot/copy your output into a doc file, then output it
as a report.pdf file. Submit both your report file and source code (.java) into Canvas


Unformatted Attachment Preview

CSC1850 OOP
Homework 4 (100 points)
Due by 11:59 pm 11/16/2023
Exception Handling and Text I/O with Command-Line Arguments
In this assignment, you will create a Java program that reads and writes data from and to text
files while handling exceptions. The program will accept two command-line arguments: the
input text file and the output text file. It will read data from the input file, perform some
operations on the data, and then write the results to the output file. Additionally, you will
implement exception handling to handle potential errors gracefully.
Requirements:
1. The program accepts two command-line arguments: the input file and the output file. (10
points)
2. Implement exception handling to handle the following scenarios (30 points):

If the input file specified as the first command-line argument is not found, display an
error message and terminate the program.
• If there are non-integer values (e.g., string, real numbers) in the input file, catch the
exception and display an error message for each invalid value. The program should
continue reading the next valid value.
• If the input file is empty, display a message indicating that the file is empty and terminate
the program.
3. Read the integers from the input file, calculate their sum, average, minimum, and maximum,
and store these values in variables. (20 points)
4. Create and write to the output text file specified as the second command-line argument, as
shown in the previous assignment. (20 points)
5. Use appropriate exception handling for file I/O, such as handling file not found or write
errors, and display informative error messages in case of any issues. (20 points)
Sample Usage:
To run the program, open the terminal and use the following command:
java YourProgramName input.txt output.txt
Sample Output:
If “input.txt” contains:
Hello 10 20 30
40 50 1.0
5.20 abc uncp ?
After running the program with the command provided, “output.txt” should contain:
Sum: 150
Average: 30
Minimum: 10
Maximum: 50
Hints:





Use args[0] and args[1] to access the command-line arguments for the input and output
file names.
Use a try-catch block to catch exceptions related to file operations.
For reading the input file, you can use a Scanner object.
For writing to the output file, you can use a PrintWriter object.
Use the hasNextInt() method to check if the next token is an integer before reading it.
Submission:
Describe how to run your program, and screenshot/copy your output into a doc file, then output it
as a report.pdf file. Submit both your report file and source code (.java) into Canvas.
Submission don’t follow the instruction shall have significant point deduction!

Purchase answer to see full
attachment