创建大的数据集
package com.sugarpie.classtest19;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Random;
/**
* chapter 12 12.24 创建大的数据集
*
* @author sugarpie
* @create 2021-06-01-8:50
*/
public class Filetest {
public static void main(String[] args) throws FileNotFoundException {
File file = new File("F:\\JUFE\\java\\Salary.txt");
if (file.exists()){
System.out.println("File already exists");
System.exit(1);
}
PrintWriter output = new PrintWriter(file);
for (int i = 0; i < 1000; i++) {
Random r = new Random();
int a = r.nextInt(3);
double b = r.nextDouble();
String level = "";
String salary = "";
switch (a){
case 0:
level = " assistant ";
salary = String.format("%.2f", (b * (80000 - 50000) + 50000));
break;
case 1:
level = " associate ";
salary = String.format("%.2f", (b * (110000 - 60000) + 60000));
break;
case 2:
level = " full ";
salary = String.format("%.2f", (b * (130000 - 75000) + 75000));
}
output.println("FirstName" + (i + 1) + " LastName" + (i + 1) + level + salary); ;
}
output.close();
}
}
运行后打开txt文件: