Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java This method will read in an input file a line at a time and add any valid account information to an AccountList. The file

java

This method will read in an input file a line at a time and add any valid account information to an AccountList. The file is formatted so that each line is a separate account. Each line has the format:

The account numbers do not have spaces in them but there is a space between the account number and the balance. See below for an example.

The input files may have errors in them. If a line is incomplete or otherwise corrupted, then it should not be added to the list, but any remaining lines should be processed.

If a line has too much information (i.e. it has values after the balance), any additional information should be ignored.

Create an AccountList that will store the data read in.

Use a Scanner to read from a file with the given file name (the parameter). For each line of input, read in the full line (check the Scanner class to see how to read in an entire line at one time).

With each line, create a new Scanner (use a different variable from the Scanner above) and use that new Scanner to read in the account number and balance. If they are successfully read in, add it to the list.

If the file cannot be opened, then the method should return null.

try-catch blocks will make this easy to do.

Dividing this method into a couple of separate methods may make this easier to do.

4. The AccountFileIO class can be tested by creating a set of files with data expected, calling parseFile and then checking to see if the AccountList returned has the data from the file.

When creating a test file, put it in the project directory and not the package directory. If it is in the project directory, you should be able to do open the file with just the file name.

myFileIO.parseFile("test1.txt");

If it is not in the project directory, you will need to supply a path to the file.

Sample input:

DHH-2180 110.25

TOB-6851 -258.45

JNO-1438 375.95 CS 145 Computer Science II

IPO-5410 834.15

PWV-5792 793.00

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

T Sql Window Functions For Data Analysis And Beyond

Authors: Itzik Ben Gan

2nd Edition

0135861446, 978-0135861448

More Books

Students also viewed these Databases questions

Question

3. What is a core competency?

Answered: 1 week ago

Question

=+31-1 Define memory, and explain how memory is measured.

Answered: 1 week ago