Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8654299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:45:12+00:00 2026-06-12T14:45:12+00:00

It works and everything, but it looks horrible. All we’re given to draw data

  • 0

It works and everything, but it looks horrible. All we’re given to draw data from is a text file with the data on hockey players. We then take this data and create players from it. Then make a list of these players. At no point are we given each team’s amount of wins, so I’m almost wondering if this is the best you can do.

Basically, what it wants to accomplish is to find the team with the most wins. This is found by the winning goals of each player being totalled, and judging by which team they were from, counting it for that team.

I accomplished this by creating the list of teams as Team objects by going through all the players and finding unique team names.

I then went through the player list and if the player’s team was equal to the current team being looked at, it would give them points for the winning goals.

Then, in yet another for loop, find the team with the highest amount of these goals.

Return this team.

That’s a total of four for loops for one little task. It seems gross.

    /**
     * Returns the team with the most wins
     */
    public Team getTeamWithMostWins() {
        Team teamWithMostWins = new Team();
        List<Team> teams = new List<Team>();

        if (!players.isEmpty()) {

            // Compile the List of teams
            for (int i = 0; i < players.size(); i++) {
                if (!teams.contains(players.get(i).getTeam())) {
                    teams.add(new Team(players.get(i).getTeam()));
                }
            }

            // Set the wins for the teams
            for (int i = 0; i < players.size(); i++) {
                String team = players.get(i).getTeam();
                int winningGoals = players.get(i).getWinningGoals();

                // Go through the teams List to set the points
                for (int j = 0; j < teams.size(); j++) {
                    // If the current player's team is equal to the current team in the loop
                    if ((teams.get(j).getName()).equals(team)) {
                        teams.get(j).incrementWinsBy(winningGoals);
                    }
                }
            }

            int mostWins = teams.get(0).getWins();

            // Find the team with the most wins
            for (int i = 1; i < teams.size(); i++) {
                if (teams.get(i).getWins() > mostWins) {
                    teamWithMostWins = teams.get(i);
                }
            }

        }
        else {
            teamWithMostWins = null;
        }

        return teamWithMostWins;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:45:13+00:00Added an answer on June 12, 2026 at 2:45 pm

    As Jordan Denison pointed out in the comments, you can used a for-each loop. See below for an example.

    In addition, currently you will only get the last team which has more wins than the first team. In order to get the team with the most wins you have to update the most wins:

    int mostWins = teams.get(0).getWins();
    
    // Find the team with the most wins
    for(Team team : teams) {
        if (team.getWins() > mostWins) {
            teamWithMostWins = team;
            mostWins = team.getWins(); // <--- Update the most wins every time you find a team with more wins
        }
    }
    

    Update

    In addition, consider using a map as shown in the other answers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to recive RemoteObject from my service. Everything works fine but my code
I started using Zend_Paginator, it works everything fine but I noticed that there is
The following bit of code works great in everything but IE. In IE, the
I'm getting a 404 on my server (IIS 7) but everything works fine on
i am developing an app which has a evernote integration,everything works perfect but my
I'm using Spreadsheet::WriteExcel packet to create some Excel files. Everything works fine but when
Trying out the example usage of codebrew rails-backbone , everything works fine but the
Everything works with no errors, but in the xml, tvfinalgrade stays 0.0... Why isn't
I have my pickerview set up and everything works fine, but right now I
I have a problem with a mouseover script. Everything works as it should but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.