Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a complete Java program in a file called FilterSort.java that reads all the tokens from a file named data.txt that is to be found

image text in transcribed

Write a complete Java program in a file called FilterSort.java that reads all the tokens from a file named data.txt that is to be found in the same directory as the running program. The program should ignore all tokens that cannot be read as an integer and read only the ones that can. After reading all of the integers, the program should print all the integers back to the screen, one per line, from the smallest to the largest. For example if data.txt contains 10 Sfive 10 1.5 2 2.0 20 Then your program should print to the screen 10 10 20 Your program should not prompt the user for anything and should print nothing except the sorted list of integers (if there are no integers your program should print nothing). If the file does not exist, then your program should instead print exactly "File not found" and exit. Your program should start by allocating an array of size 8 and fill it with the first 8 tokens. On the ninth token, it should replace the array with one of size 16 and copy all the integers already read. On the 17th token, it should replace the array with one of size 32 and copy all the integers already read. Etc. Since this doubling the size of an array is a repeated operation that is easily factored into a coherent chunk, you should write a method that performs this task. Also, be sure you read the textbook about the Arrays class and the java documentation about the static method Arrays.sort(a, fromIndex, toIndex) You should not write your own sorting algorithm

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions

Question

Describe how language reflects, builds on, and determines context?

Answered: 1 week ago