Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program described on the next page of this document. You must use a Java IDE to complete this assignment. Use IOLab.java to do

Write a program described on the next page of this document. You must use a Java IDE to complete this assignment. Use IOLab.java to do the following:

1. Your finished program must exclude all the throws IOException lines. Remove the throws IOException from the readData first. Don't remove the throws IOExcpetion from the main method until the program is completed and everything else working.

2. Include competent exception handlers for the readData and writeData methods in this assignment.

3. See the example IO programs posted on the course web-site for assistance.

4. The file to read is located on the last page of this document. Copy and paste the data on the last page into a simple text file.

5. The first two entries in the file represent: 1) the number of rows, 2) and the number of columns. Read the remaining numbers from the input file data and fill a two-dimensional array by rows. For example, if the number of rows is 6 and the number of columns is 4, then the next 4 numbers in the input file make up the first row of numbers in your 2-D array. Use a nested loop to fill the 2-D array.

6. Write an instance method and name it toString. This method will return a string containing the 2-D array as a table. Use the String.format( ) method to build your string. The decimal point should be aligned in each column of output.

7. Prompt the user for an output file-name to write. Write the number of rows and columns into the first two lines of the file. The output file name must be different than the input file name.

8. Write the contents of your 2-D data array into the file using the printf method to format your values in a row-column format using format elements. The decimal point should be aligned in each column. Write the data with four digits to the right of the decimal.

9. Add logic to recover from an exception in the readData method. If the user enters a nonexistent file name, prompt the user for another file name.

image text in transcribed

public class IOLab // rows // data. Iength; data [i].length; private double [][] data; cols public static void main( String [ args throws IOException 10Lab fileTest new 10Lab ( ); fileTest.readData System.out.println( fileTest.tostring) fileTest.writeData) public void readData() throws IOException Scanner console new Scanner ( System.in ); System.out.print "Please enter a file name to read: " String inFile = console . next(); /I connect to the file File file = new File ( inFile ); scanner tokens = new scanner( file ); // buffer the data int nrows = tokens.nextInt(); // get the number of rows. // 1. get the number of cols // 2. allocate space for the 2-d data array instance field: 11 3. write a nested loop to read the data into the data array /1 4. close the file: ) // end readData () public void writeData throws IOException

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions