Bot.java
1 import java.io.BufferedReader; 2 import java.io.FileReader; 3 import java.io.IOException; 4 import java.util.ArrayList; 5 6 public class Bot { 7 static final String ds = "$"; 8 9 public static void main(String[] args) throws IOException { 10 } 11 12 public static Symbol[] getRandomStocks(int num) throws IOException { 13 String fileName = "stocks.txt"; 14 String line = null; 15 FileReader fileReader; 16 ArrayList<String> stocks = new ArrayList<String>(); 17 Symbol[] randomStocks = new Symbol[num]; 18 19 try { // Gets all stocks and adds them to ArrayList<String> stocks 20 fileReader = new FileReader(fileName); 21 BufferedReader bufferedReader = new BufferedReader(fileReader); 22 while ((line = bufferedReader.readLine()) != null) { 23 stocks.add(line); 24 } 25 bufferedReader.close(); 26 } catch (Exception e) {} 27 28 int stocksSize = stocks.size(); 29 30 //NOTE - This method may return duplicates 31 for (int f = 0; f < num; f++) { // Adds 30 random stocks to Symbol[] 32 // randomStocks 33 int random = (int) (Math.random() * (stocksSize)); 34 randomStocks[f] = new Symbol(stocks.remove(random)); 35 } 36 return randomStocks; 37 } 38 }