import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class NumList { private ArrayList nums; public NumList( String fileName ) throws FileNotFoundException { nums = new ArrayList(); Scanner fileScanner = new Scanner( new File( fileName ) ); double num = fileScanner.nextInt(); while( fileScanner.hasNextDouble() ) { num = fileScanner.nextInt(); nums.add(num); } } public double get(int index) { return nums.get(index); } public void sort() { // simple bubble sort for( int i = nums.size()-1; i > 0; --i ) { for( int j = 1; j < i; ++j ) { if( nums.get(j) < nums.get(j-1) ) { Collections.swap(nums,j,j-1); } } } } public String toString() { String ret = ""; for( Double num : nums ) { ret += num; ret += "\n"; } return ret; } }