Java语言程序设计与数据结构(基础篇)chapter12 12.24

创建大的数据集

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文件:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值