Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help writing a program in JAVA with this problem: Attached you will find

ID: 2247423 • Letter: I

Question

I need help writing a program in JAVA with this problem:

Attached you will find a file named WorldSeriesWinners.txt. The file contains a chronological list of the winning teams in the World Series from 1903 through 2009. (the first line in the file is the name of the team won in 1903, and the last line is the name of the team that won in 2009. Note that the World Series was not played in 1904 or 1994, so those years are skipped in the file.)

Write a program that lets the user enter the name of a team, and then displays the number of times that team has won the World Series in the time period from 1903 through 2009.

Explanation / Answer

import java.io.*;
import java.util.*;

public class Winner{
   public static void main(String[] args){

       Scanner sc = new Scanner(System.in);
       System.out.print("Enter the name of team :");
       String name = sc.nextLine();
      
       try {
          File fin = new File("WorldSeriesWinners.txt");
          FileInputStream fis = new FileInputStream(fin);
          BufferedReader br = new BufferedReader(new InputStreamReader(fis));
          String line = null;
          int count = 0;
          while ((line = br.readLine()) != null) {
  if (line.equals(name))
                   count++;
   }
   br.close();
          System.out.println("The " + name + " has won " + count + " times.");
       } catch (Exception e){
          e.printStackTrace();
       }

   }
}