Writing body of AlgorithmTester and RandomNumberFileMaker
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
package Sorting;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.FileWriter;
|
||||
import java.lang.Math;
|
||||
|
||||
/**
|
||||
* This class will allow the user to make a file of random integers.
|
||||
* The user will be able to select a file name, how many numbers are in the file,
|
||||
@@ -7,4 +12,25 @@ package Sorting;
|
||||
*/
|
||||
public class RandomNumberFileMaker {
|
||||
|
||||
public RandomNumberFileMaker(String filename, int count, int min, int max){
|
||||
try{
|
||||
File randomNumbers = new File(filename);
|
||||
if(randomNumbers.createNewFile()==false){
|
||||
System.out.println("File already exists.");
|
||||
}
|
||||
else{
|
||||
FileWriter randomWriter = new FileWriter(randomNumbers);
|
||||
for(int i=0;i<count;i++){
|
||||
int rand = min + (int) (Math.random()*(max-min));
|
||||
randomWriter.write(rand);
|
||||
randomWriter.write("\n");
|
||||
}
|
||||
randomWriter.close();
|
||||
}
|
||||
}catch (IOException ex){
|
||||
System.err.println(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user