CSC1850 Object and Oriented

Description

Having Trouble Meeting Your Deadline?

Get your assignment on CSC1850 Object and Oriented  completed on time. avoid delay and – ORDER NOW

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

Explanation & Answer

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Order Now and we will direct you to our Order Page at Litessays. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

Similar Posts