RandLunch.java
@FXML protected void RandLoc(ActionEvent event){
      
      
      //try catch, to make sure the file exists, if not instructions to create
      try {
         FileInputStream fs = new FileInputStream("Lunch Locations.txt");
         BufferedReader br = new BufferedReader(new InputStreamReader(fs));
         ArrayList<String> array = new ArrayList<>();
         String strLine;
         //secondary try catch for the readline in the buffer reader
         try {
            while((strLine = br.readLine()) != null) {
               array.add(strLine);
            }
            //create random var
            Random ranLine = new Random();
   
            //determine random line
            int randomIndex = ranLine.nextInt(array.size());
   
            //output random line
            output.setText(array.get(randomIndex));
         } catch (IOException e) {
            listLoc.setText("Cannot find Lunch Locations.txt \n make sure its in the same \n directory as RandLunch.jar");
         }
      } catch (FileNotFoundException e) {
        listLoc.setText("Cannot find Lunch Locations.txt \n make sure its in the same \n directory as RandLunch.jar");
      }
   }
//randomly pick line in lunch locations text file
randomly pick line in lunch locations text file
randomly pick line in lunch locations text file
@FXML protected void RandLoc(ActionEvent event){
      try {
         FileInputStream fs = new FileInputStream("Lunch Locations.txt");
         BufferedReader br = new BufferedReader(new InputStreamReader(fs));
         ArrayList<String> array = new ArrayList<>();
         String strLine;
         try {
            while((strLine = br.readLine()) != null) {
               array.add(strLine);
            }
            Random ranLine = new Random();
            int randomIndex = ranLine.nextInt(array.size());
            output.setText(array.get(randomIndex));
         } catch (IOException e) {
            listLoc.setText("Cannot find Lunch Locations.txt \n make sure its in the same \n directory as RandLunch.jar");
         }
      } catch (FileNotFoundException e) {
        listLoc.setText("Cannot find Lunch Locations.txt \n make sure its in the same \n directory as RandLunch.jar");
      }
   }
@ FXML protected void RandLoc ( ActionEvent event ) { try { FileInputStream fs = new FileInputStream ( "Lunch Locations.txt" ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( fs ) ) ; ArrayList < String > array = new ArrayList < > ( ) ; String strLine ; try { while ( ( strLine = br . readLine ( ) ) != null ) { array . add ( strLine ) ; } Random ranLine = new Random ( ) ; int randomIndex = ranLine . nextInt ( array . size ( ) ) ; output . setText ( array . get ( randomIndex ) ) ; } catch ( IOException e ) { listLoc . setText ( "Cannot find Lunch Locations.txt \n make sure its in the same \n directory as RandLunch.jar" ) ; } } catch ( FileNotFoundException e ) { listLoc . setText ( "Cannot find Lunch Locations.txt \n make sure its in the same \n directory as RandLunch.jar" ) ; } }
randomly pick line in lunch locations text file
randomly pick line in lunch locations text file
//try catch, to make sure the file exists, if not instructions to create //secondary try catch for the readline in the buffer reader //create random var //determine random line //output random line