To begin download the text file and save it in the same fold
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 (\ ). Name your main class Hw5pr3 and your main file Hw5pr3.java.
Solution
Hi, Please find my implementation.
Please let me know in case of any issue.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Hw5pr3 {
public static void main(String[] args) throws FileNotFoundException {
// reading input file name
Scanner input = new Scanner(System.in);
System.out.print(\"Enter input filename : \");
String fileNamne = input.next();
// opening file
Scanner scanner = new Scanner(new File(fileNamne));
// creating 2-D array of string
String[][] records = new String[100][2];
int row = 0;
// reading file and storing in array
while(scanner.hasNext()){
records[row][0] = scanner.next(); // reading year
records[row][1] = scanner.nextLine(); // reading team name
row++;
}
scanner.close();
// now reading from user and searing team name
String year;
System.out.print(\"Enter year: \");
year = input.next();
while(! year.equalsIgnoreCase(\"stop\")){
int i= 0;
for(i=0; i<row; i++){
if(records[i][0].trim().equals(year)){
System.out.println(\"Winning Team: \"+records[i][1]);
break;
}
}
// if year is not in array
if( i == row){
System.out.println(year+\" not present in record\");
}
// reading next year
System.out.print(\"\ Enter year: \");
year = input.next();
}
}
}
/*
Sample run:
Enter input filename : input.txt
Enter year: 1990
Winning Team: San Francisco 49ers
Enter year: 2000
Winning Team: St. Louis Rams
Enter year: 2020
2020 not present in record
Enter year: stop
*/
###### input.txt ############
1967 Green Bay Packers
1968 Green Bay Packers
1969 New York Jets
1970 Kansas City Chiefs
1971 Baltimore Colts
1972 Dallas Cowboys
1973 Miami Dolphins
1974 Miami Dolphins
1975 Pittsburgh Steelers
1976 Pittsburgh Steelers
1977 Oakland Raiders
1978 Dallas Cowboys
1979 Pittsburgh Steelers
1980 Pittsburgh Steelers
1981 Oakland Raiders
1982 San Francisco 49ers
1983 Washington Redskins
1984 Los Angeles Raiders
1985 San Francisco 49ers
1986 Chicago Bears
1987 New York Giants
1988 Washington Redskins
1989 San Francisco 49ers
1990 San Francisco 49ers
1991 New York Giants
1992 Washington Redskins
1993 Dallas Cowboys
1994 Dallas Cowboys
1995 San Francisco 49ers
1996 Dallas Cowboys
1997 Green Bay Packers
1998 Denver Broncos
1999 Denver Broncos
2000 St. Louis Rams
2001 Baltimore Ravens
2002 New England Patriots
2003 Tampa Bay Buccaneers
2004 New England Patriots
2005 New England Patriots
2006 Pittsburgh Steelers
2007 Indianapolis Colts
2008 New York Giants
2009 Pittsburgh Steelers
2010 New Orleans Saints
2011 Green Bay Packers
2012 New York Giants
2013 Baltimore Ravens
2014 Seattle Seahawks
2015 New England Patriots



