Thank you for visiting java Lab14Sort java import java util Scanner import java io File import java io IOException import java util ArrayList public class Lab14Sort public static void. This page is designed to guide you through key points and clear explanations related to the topic at hand. We aim to make your learning experience smooth, insightful, and informative. Dive in and discover the answers you're looking for!
```java
Lab14Sort.java
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
public class Lab14Sort {
public static void main(String[] args) throws IOException {
String filename = null;
Scanner scnr = null;
Scanner tokens = null;
double value = 0.0;
// 1. Instantiate an ArrayList object named myList for type Double.
ArrayList myList = new ArrayList<>();
// This logic will use the command line argument or prompt for input:
if (args.length != 0) { // args is an array!
filename = args[0];
} else {
scnr = new Scanner(System.in);
System.out.println("Enter filename:");
filename = scnr.nextLine().strip();
}
// 2. Open the file to read using the File and Scanner classes:
File fHandle = new File(filename);
tokens = new Scanner(fHandle);
int counter = 0; // This counts the numbers as they are read.
myList.add(tokens.nextDouble()); // put first item in list.
++counter; // Count it.
while (tokens.hasNext()) {
// 3. Get the next number from the data file.
value = tokens.nextDouble();
// 4. Place the current number into your list and count it.
myList.add(value);
++counter;
} // repeat until all numbers are loaded into the ArrayList.
// 5. Confirm your ArrayList is populated with the data by printing
System.out.println("Data in ArrayList:");
for (Double num : myList) {
System.out.println(num);
}
if (scnr != null) {
scnr.close();
}
if (tokens != null) {
tokens.close();
}
}
}
```
**data14.txt**
```
29.4 7.7 19.454 23.6
3.33 2.5 47.5 55.1
6.9 11.0 97.8 4.45 12.3
3.33 5.454 62.8 1.0 99.8
```
// This logic will use the command line argument or prompt for input:
if (args.length != 0) { // args is an array!
filename = args[0];
} else {
scnr = new Scanner(System.in);
System.out.println("Enter filename:");
filename = scnr.nextLine().strip();
}
// 2. Open the file to read using the File and Scanner classes:
File fHandle = new File(filename);
tokens = new Scanner(fHandle);
int counter = 0; // This counts the numbers as they are read.
myList.add(tokens.nextDouble()); // put first item in list.
++counter; // Count it.
while (tokens.hasNext()) {
// 3. Get the next number from the data file.
value = tokens.nextDouble();
// 4. Place the current number into your list and count it.
myList.add(value);
++counter;
} // repeat until all numbers are loaded into the ArrayList.
// 5. Confirm your ArrayList is populated with the data by printing
System.out.println("Data in ArrayList:");
for (Double num : myList) {
System.out.println(num);
}
if (scnr != null) {
scnr.close();
}
if (tokens != null) {
tokens.close();
}
}
}
```
**data14.txt**
```
29.4 7.7 19.454 23.6
3.33 2.5 47.5 55.1
6.9 11.0 97.8 4.45 12.3
3.33 5.454 62.8 1.0 99.8
```