Question: The following program read in the team stats from the input and display ranks the team based on the percentage of win. The team with

The following program read in the team stats from the input and display ranks the team based on the percentage of win. The team with the highest percentage of wins should display first.

The following program read in the team stats from the input anddisplay ranks the team based on the percentage of win. The team

8 import java.util.Scanner; 2 import java.util.ArrayList; 3 import java.util.Collections; 4 import java.util.Comparator.; 5 6 public class Test I public static void main(String[] args) { Scanner stdin = new Scanner(System.in); ArrayList teamStats = new ArrayList(); 10 while (stdin.hasNextLine()) { 11 // read a line and break to three pieces using space 12 String[] fields = stdin.nextLine().split(" "); 13 14 teamStats.add(new TeamStat(fields [0], Integer.parseInt(fields[1]), Integer.parseInt(fields [2]))); 15 } 16 17 // your code starts here 18 19 // your code ends here 20 for (TeamStat ts : teamStats) { 21 System.out.println(ts.getTeam() + "\t" + ts.getWin() + "\t" + ts.getLoss()); } 23 stdin.close(); 24 } 25 }| 22 2 1 class TeamStat { String team; int win; int loss; public TeamStat(String team, int win, int loss) { this.team = team; this.win = win; this.loss = loss; } public String getTeam() { return team; } public int getWin() { return win; } public int getLoss() { return loss; } 1

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!