scanner library showing element not found exception

Solutions on MaxInterview for scanner library showing element not found exception by the best coders in the world

showing results for - "scanner library showing element not found exception"
Lennard
15 Nov 2020
1import java.util.ArrayList;
2import java.util.Collections;
3import java.lang.Object;
4
5import java.io.File;
6import java.io.FileNotFoundException;
7import java.util.Scanner;
8
9public class Bracket_Creator{
10
11
12    public static void main(String[] args) throws FileNotFoundException
13    {   
14
15        String first_name = "";
16        String last_name = "";
17        String school = "";
18        int weight = 0;
19        int confer_win = 0;
20        int confer_loss = 0;
21        int overall_wins = 0;
22        int overall_loss = 0;
23        ArrayList<Wrestler> list = new ArrayList<Wrestler>();
24        int i = 0;
25        boolean flag = true;
26
27        //new scanner instance
28        Scanner scanner = new Scanner(new File("wrestlers.csv"));
29
30        //the seperator for the file
31        scanner.useDelimiter(",");
32        while(scanner.hasNext()){
33            first_name = scanner.next();
34            last_name = scanner.next();
35            school = scanner.next();
36            weight = scanner.nextInt();
37            confer_win = scanner.nextInt();
38            confer_loss = scanner.nextInt();
39            overall_wins = scanner.nextInt();
40            overall_loss = scanner.nextInt();
41            list.add(new Wrestler(first_name,last_name,school,weight,
42                confer_win,confer_loss,overall_wins,overall_loss));
43
44            System.out.println((list.get(i).get_first_name()));
45            i++;
46
47
48        }//end while
49        scanner.close();
50
51
52
53        //make the percentages for the wrestlers
54        for (i = 0; i < list.size(); i++){
55            (list.get(i)).determine_conf_percentage((list.get(i)).get_confer_wins(), (list.get(i)).get_confer_losses());
56            (list.get(i)).determine_overall_percentage((list.get(i)).get_overall_wins(), (list.get(i)).get_overall_losses());
57
58        }//end for loop
59        //set rank
60        while ( flag )
61        {
62            flag= false;    //set flag to false awaiting a possible swap
63            for( i=0;  i < list.size() -1;  i++ )
64            {
65                   if ((list.get(i)).get_confer_percentage() < (list.get(i+1)).get_confer_percentage() )  
66                   {
67
68                        Collections.swap(list, i, i+1);
69                        flag = true;
70
71                    }//end if
72            }//end for 
73
74        }//end while
75
76        //set rank value
77        for (i = 0; i< list.size(); i++){
78            (list.get(i)).set_rank(i + 1);
79        }//end for loop
80
81        for (i = 0; i< list.size(); i++){
82            System.out.println((list.get(i)).get_first_name());
83        }
84            System.out.println("");
85
86        /*
87        *
88        *
89        *Create the Bracket!
90        *
91        *
92        */
93        int j = 1; //J here is for the end of the list, every time you go through
94        //add one to J in the loop to keep on coming in from the other end of
95        //the list
96        for (i = 0; i< (list.size()/2); i++){
97            if (i == 0) {//first pass thru the list
98                System.out.println((list.get(i)).get_first_name());
99                System.out.println((list.get(list.size()-j)).get_first_name());
100                System.out.println();
101                j++;
102                }//end if
103
104            else{
105                System.out.println((list.get(i)).get_first_name());
106                System.out.println((list.get(list.size()-j)).get_first_name());
107                System.out.println();
108                j++;
109
110                }//end else
111
112        }//end for
113
114
115
116
117    }//end main
118
119
120}//end bracket_creator class