Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Copy the file ints into the project folder. (file ints contains random integers and they are on each line) // create a new int.txt file

Copy the file ints into the project folder. (file ints contains random integers and they are on each line) // create a new int.txt file in your project folder and just put some random integers (one integer on each line) (you can try 19 integers )

Create a method "void sortInts(String filename)" that

  1. Reads the data from the file one line at a time and saves it into an array.
  2. Sorts the array from smallest item to largest
  3. Writes the array of data into the new file, without writing any null values.

- Open your new file to check that the file has been properly created.

- You can assume that there are less than 100 items in the file.

- The new file should be called filename_sorted

To sort an array, go through each item once (outer loop) and for each item to the right (inner loop), check if the item to the right is greater (otherwise swap them using a temporary variable)

The code must pass all the following tests in the photo attached

and use file objects, scanner objects, printwriter

do not use string buffer.

image text in transcribed

Test Expected Got X FILE NOT CREATED sortInts("ints.txt"); testFileSorting("ints.txt"); X FILE NOT CREATED sortInts("ints2.txt"); testFileSorting("ints2.txt"); File was not found File was not found sortInts("nofile.txt"); testFileSorting("nofile.txt")

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

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions