Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

This is for an intermediate Java class.. I cant get the file to read properly. Its spelled correctly and located in the proper place so

This is for an intermediate Java class..

I cant get the file to read properly. Its spelled correctly and located in the proper place so something is wrong with that. I could use a little help. Thank you.

The file, Program3.txt, on the I: drive contains a chronological list of the World Series winning teams from 1903 through 2019. The first line in the file is the name of the team that won in 1903, and the last line is the name of the team that won in 2019. (Note that the World Series was not played in 1904 or 1994. There are no entries in the file indicating this.)

Write a program that reads this file only once and creates a HashMap in which the keys are the years and each keys associated value is the name of the team that won that year.

The program should also create a HashMap in which the keys are the names of the teams and each keys associated value is the number of times the team has won the World Series.

The program should prompt the user for a year in the range of 1903 through 2019 (validate the user input). It should then display the name of the team that won the World Series that year and the number of times that team has won the World Series.

Allow the user to run the program as many times as possible until a sentinel value of zero (0) has been entered for the year. No input, processing or output should happen in the main method. All work should be delegated to other non-static methods. Include the recommended minimum documentation for each method.

Boston Americans New York Giants Chicago White Sox Chicago Cubs Chicago Cubs Pittsburgh Pirates Philadelphia Athletics Philadelphia Athletics Boston Red Sox Philadelphia Athletics Boston Braves Boston Red Sox Boston Red Sox Chicago White Sox Boston Red Sox Cincinnati Reds Cleveland Indians New York Giants New York Giants New York Yankees Washington Senators Pittsburgh Pirates St. Louis Cardinals New York Yankees New York Yankees Philadelphia Athletics Philadelphia Athletics St. Louis Cardinals New York Yankees New York Giants St. Louis Cardinals Detroit Tigers New York Yankees New York Yankees New York Yankees New York Yankees Cincinnati Reds New York Yankees St. Louis Cardinals New York Yankees St. Louis Cardinals Detroit Tigers St. Louis Cardinals New York Yankees Cleveland Indians New York Yankees New York Yankees New York Yankees New York Yankees New York Yankees New York Giants Brooklyn Dodgers New York Yankees Milwaukee Braves New York Yankees Los Angeles Dodgers Pittsburgh Pirates New York Yankees New York Yankees Los Angeles Dodgers St. Louis Cardinals Los Angeles Dodgers Baltimore Orioles St. Louis Cardinals Detroit Tigers New York Mets Baltimore Orioles Pittsburgh Pirates Oakland Athletics Oakland Athletics Oakland Athletics Cincinnati Reds Cincinnati Reds New York Yankees New York Yankees Pittsburgh Pirates Philadelphia Phillies Los Angeles Dodgers St. Louis Cardinals Baltimore Orioles Detroit Tigers Kansas City Royals New York Mets Minnesota Twins Los Angeles Dodgers Oakland Athletics Cincinnati Reds Minnesota Twins Toronto Blue Jays Toronto Blue Jays Atlanta Braves New York Yankees Florida Marlins New York Yankees New York Yankees New York Yankees Arizona Diamondbacks Anaheim Angels Florida Marlins Boston Red Sox Chicago White Sox St. Louis Cardinals Boston Red Sox Philadelphia Phillies New York Yankees San Francisco Giants St. Louis Cardinals San Francisco Giants Boston Red Sox San Francisco Giants Kansas City Royals Chicago Cubs Houston Astros Boston Red Sox Washington Nationals

package program3; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.HashMap; import java.util.Scanner;

public class worldSeriesInfo { public static void main(String[] args) throws FileNotFoundException {

worldSeriesInfo myObj = new worldSeriesInfo(); myObj.readFile(); }

public void readFile() throws FileNotFoundException { try (Scanner input = new Scanner(new FileReader("program3.txt"))) { HashMap map = new HashMap(); while(input.hasNextLine()) { String[] teams = input.nextLine().split("\t"); map.put(teams[0],Integer.parseInt(teams[1])); } System.out.println(map); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions