Question: Much of the code has been provided for you, including code to sort the teams by win percentage and print them out ( study this

Much of the code has been provided for you, including code to sort the teams by win percentage and print them
out (study this code as it may be useful in future assignments).
Finish implementing the loadData() method by adding code to open the mlb_nl_2011.csv data file (in the
directory), process it line-by-lie and create individual instances.
3.2.1 File Output
In this activity, you will write a method to output the sorted team list to a file rather than the standard output. To
output to a file, use the class which supports easy output to files. A full example:
Add the following method to the Baseball.java source file that takes a list of teams and an output file name and
outputs the team data to that file.
The format is up to you
Call your method from the main and test that it works
Add javadoc-style documentation to your method. Remember that all classes and non-trivial methods require
documentation.
package unl.cse;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Processes a comma-separated value (CSV) file of win/loss data from the 2011
* National League MLB season. It sorts the teams (best record to worst) and
* prints a report to the standard output.
*
* @author cbourke
*
*/
public class Baseball {
private static final String FILE_NAME = "data/mlb_nl_2011.csv";
/**
* This method loads MLB team data from the CSV file
* specified by {@link #FILE_NAME} and instantiates
* and returns a list of {@link Team}s.
*
* @return
*/
public static List loadData(){
List teams = new ArrayList>();
// TODO: write code to open the file, process it line-by-line
// to create team instances and add them to the list.
//
// Be sure to close the scanner
return teams;
}
//TODO: implement the file output method
public static void main(String args[]){
List teams = loadData();
System.out.println("Teams: ");
for (Team t : teams){
System.out.println(t);
}
Collections.sort(teams, new Comparator(){
@Override
public int compare(Team a, Team b){
return b.getWinPercentage().compareTo(a.getWinPercentage());
}
});
System.out.println("
Sorted Teams: ");
for (Team t : teams){
System.out.println(t);
}
//TODO: call your file output method with the sorted teams
}
}
 Much of the code has been provided for you, including code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!