Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DigitsAndWrappers Remember the required import statements. Remember the throws statement where necessary in the appropriate method headers This program consists of a main method and

DigitsAndWrappers

Remember the required import statements.

Remember the throws statement where necessary in the appropriate method headers

This program consists of a main method and two additional methods addDigitsToArrayList and outputResults. You can use the dwinput.txt file to test your program.

main method

Create an ArrayList of type Integer

Create a Scanner to read in from the keyboard

Request and read in the name of the physical input file.

Create a Scanner for this file or handle the case where the file doesnt exist

Request and read in the name for a physical output file.

Create a PrintWriter that will write to the physical file.

While there is another line to read in from the input file with the Scanner

Read in the line as a String

Call addToArrayList with references to the String and the ArrayList as parameters

Call outputResults with references to the String, the ArrayList and the PrintWriter as parameters

Use a method to clear the ArrayList

Remember to close the PrintWriter object

addDigitsToArrayList method

Accepts a reference to a String and to an ArrayList of type Integer as parameters, with a void return

For each character in the String

If the character is a digit (0 to 9)

Convert the character to an int (you may use the static Character method

int getNumericValue(char). Or any other mechanism you wish

Add the int to the ArrayList after creating an Integer object using valueOf

outputResults method

Accepts a reference to a String, to an ArrayList of type Integer, and to a PrintWriter as parameters with a void return

Produce the output as shown below.

This is the String followed by a printout of the ArrayList using the Arraylist toString() method

Sample input:

Please enter the name of the input file:

dwinput.txt

Please enter the name of the output file:

dwoutput.txt

Output in dwoutput.txt based on dwinput.txt:

ABC 123 678 2NOy [1, 2, 3, 6, 7, 8, 2]

4 8 9 2 X Y 7 [4, 8, 9, 2, 7]

A1B2C3D4E5 [1, 2, 3, 4, 5]

1 0 UV 888!!! [1, 0, 8, 8, 8]

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

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

Bachelors degree in Information Systems or Statistics

Answered: 1 week ago