Java Array and File I/O

Verified

Added on  2019/09/16

|1
|277
|217
Practical Assignment
AI Summary
This practical assignment focuses on Java programming, specifically dealing with array manipulation and file input/output operations. Students are tasked with creating three methods: `arrayBuilder`, which creates a string array of a specified length (throwing an exception for negative input); `writeArray`, which writes a string array to a text file (handling potential exceptions); and `readFile`, which reads a text file into an ArrayList of strings (also handling exceptions). The main method then calls these three methods, demonstrating their functionality and exception handling. The assignment emphasizes practical application of core Java concepts and robust error handling.
Document Page
Problems:
1. Write a method called arrayBuilder that takes an integer parameter (length), returns
an array of Strings,
and is declared to throw an Exception. If the parameter passed is a negative value,
throw
an Exception. Otherwise, build and return an array of Strings with size based on
the parameter passed. (2 points)
2. Write a method called writeArray that takes two parameters: an array of Strings and
a String (fileName), and returns nothing. Write the array of Strings to a text file
named using the fileName parameter. Make sure to catch any Exception that
might be thrown. (3 points)
3. Write a method called readFile that takes a String parameter (fileName) and
returns an ArrayList of Strings. The method reads the text file (fileName) and
populates the ArrayList with an element for each line in the file. The returns the
populated ArrayList. Make sure to catch any Exception that
might be thrown. (3 points)
4. Call each of the methods above from the main method.
The pseudocode for the main method will be as given below.
Make sure to catch any Exception that
might be thrown. (2 points)
Call arrayBuilder passing the size of the array that you want returned
Pass the array and a file name to the writeArray method
Pass the file name to the readFile method
In the main method loop through the returned ArrayList to print
its contents to the command line
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
[object Object]