To begin, download the text file and save it in the same folder as your java source files: http://courses.cs.tamu.edu/hurley/cpsc111/homework/SuperBowlWinners.txt Next, write a program that opens and reads the data from this file into a 2D array. Each row of your array corresponds to one line of the file. The first column should contain the year and the second column the full team name. Then ask the user to enter a year, and output the team that won the SuperBowl that year. Give an error if the year is not in the data. Let the user keep entering a year until they enter STOP. Hint: Remember that Scanner gives you different options for reading input. For example, the next() method stops reading when it sees a space, tab, or newline character, while the nextLine() method only stops when it sees a newline character (\ ).
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class TextFileExample { public static void main(String[] args) { String fileName = \" http://courses.cs.tamu.edu/hurley/cpsc111/homework/SuperBowlWinners.txt \"; Scanner inputStream = null; System.out.println(\"The file \" + fileName + \"\ contains the following lines:\ \"); try { inputStream = new Scanner(new File(\" http://courses.cs.tamu.edu/hurley/cpsc111/homework/SuperBowlWinners.txt \"));//The txt file is being read correctly. String line = inputStream.nextLine(); String[] numbers = line.split(\"\"); int[][] courses = new int[4][7]; for (int row = 0; row < 4; row++) { for (int column = 0; column < 7; column++) { superbowlwinners[row][column] = http://courses.cs.tamu.edu/hurley/cpsc111/homework/SuperBowlWinners.txt );//Is this correct? } } } catch(FileNotFoundException e) { System.out.println(\"Error opening the file \" + fileName); System.exit(0); } while (inputStream.hasNextLine()) { String line = inputStream.nextLine(); System.out.println(line); } inputStream.close(); } }