MainSeniorHelper.java
/*
    while loop goes through the file to count
    how many lines are in the file
    then uses that num to use as a base for the
    randomized var
     */
while loop goes through the file to count
how many lines are in the file
then uses that num to use as a base for the
randomized var
while loop goes through the file to count how many lines are in the file then uses that num to use as a base for the randomized var
static public String generate() throws IOException {
        int totalLines = 0;
        File file = new File("randomQuotes.txt");
        BufferedReader br = null;
        br = new BufferedReader(new FileReader(file));
        while ((br.readLine()) != null) {
            totalLines++;
        }
        br.close();
        br = new BufferedReader(new FileReader(file));
        Random random = new Random();
        int randomInt = random.nextInt(totalLines);
        int count = 0;
        String gen;
        while ((gen = br.readLine()) != null) {
            if (count == randomInt) {
                br.close();
                return gen;
            }
            count++;
        }
        br.close();
        return "gen";
    }
static public String generate ( ) throws IOException { int totalLines = 0 ; File file = new File ( "randomQuotes.txt" ) ; BufferedReader br = null ; br = new BufferedReader ( new FileReader ( file ) ) ; while ( ( br . readLine ( ) ) != null ) { totalLines ++ ; } br . close ( ) ; br = new BufferedReader ( new FileReader ( file ) ) ; Random random = new Random ( ) ; int randomInt = random . nextInt ( totalLines ) ; int count = 0 ; String gen ; while ( ( gen = br . readLine ( ) ) != null ) { if ( count == randomInt ) { br . close ( ) ; return gen ; } count ++ ; } br . close ( ) ; return "gen" ; }
while loop goes through the file to count
how many lines are in the file
then uses that num to use as a base for the
randomized var
while loop goes through the file to count how many lines are in the file then uses that num to use as a base for the randomized var