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

Write a program that lets the user enter the name of a team, and then displays t

ID: 3531063 • Letter: W

Question

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. This file contains a chronological list of the winning teams in the World Series from 1903 through 2009. (The first linein 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 2009. note that the World Series was not played in 1904 or 1994, so those years are skipped in the file.) The name of the file is WorldSeriesWinners.txt 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

Explanation / Answer

you can do so by creating an String array,input, of size 2009-1903+1. Read in info to that array.


Look here for reading in line-by line




http://www.roseindia.net/java/beginners/java-read-file-line-by-line.shtml




but instead of printing out, it be something like this:


array[i]=strLine;




Afterward, make two more arrays- one String array to hold all unque teams and an integer array to hold the counts of those unique String


you would also need integer UniqueTeamCount.






UniqueTeamCount=0;

int[] counts = new int[size];

String[] teams= new String[size];




int index;


for(int i=0;i<size;i++){

index=-1;

for(int j=0;j<UniqueTeamCount;j++){

if(input[i].equals(teams[j])){

index=j;

break;

}

}


if(index==-1){ //not found


teams[UniqueTeamCount]=input[i];

counts[UniqueTeamCount]=1;


UniqueTeamCount++;

}


else{

counts[index]++;

}


}







Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote