/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package lab7exfiles; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Random; import java.util.Scanner; /** * * @author jcmtiernan */ public class Lab7exFiles { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { final int BUNCH_AMT = 50; int[][] bunch = new int[50][3]; double[] dblBunch = new double[50]; String[] strBunch = new String[50]; String fileName = makeRandomDataFile(50, 500, 35, 1000); File inBunch = new File(fileName); Scanner inData = new Scanner(inBunch); int row = 0; while (inData.hasNextLine()) { // read the data from one line of the file // ints into bunch, double in dblBunch, String into strBunch bunch[row][0] = inData.nextInt(); dblBunch[row] = inData.nextDouble(); strBunch[row] = inData.next(); bunch[row][1] = inData.nextInt(); bunch[row][2] = inData.nextInt(); System.out.println(" Read in "+bunch[row][0]+" and "+dblBunch[row]+ " and "+strBunch[row]+" and "+bunch[row][1]+" and "+bunch[row][2]); inData.nextLine(); } } public static String makeRandomDataFile( int maxLines, int rangeTeamNum, int rangeRP, int rangeQP) throws IOException { String name = "TeamBunchOData.txt"; PrintWriter bw = new PrintWriter(name); //BufferedWriter bw = new BufferedWriter(fw); int teamNum, randRP, randQP; double randDbl = 0; Random randGen = new Random(); //creating Random number generator String team = "Team"; for(int k = 0; k < maxLines; k++) { teamNum = randGen.nextInt(rangeTeamNum); randRP = randGen.nextInt(rangeRP); // notice that two values are being printed randQP = randGen.nextInt(rangeQP); randDbl = randRP * randQP * .1; bw.write(String.format("%d %f %s %d %d", teamNum, randDbl, team, randRP,randQP)); bw.println(); } bw.close();// be sure to close BufferedWriter return name; } }