Object-Oriented Programming with Java, part I – Exercise 13

This program imports the NHL statistics and then provides various ways to sort them.

My Code

import java.util.Scanner;
import nhlstats.NHLStatistics;

public class Main {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);

        System.out.println("Top ten by points");
        NHLStatistics.sortByGoals();    // orders the players by goals
        NHLStatistics.top(10);          // prints top 10
        
        System.out.println("");         // white space
        
        System.out.println("Top twenty-five by penalties");
        NHLStatistics.sortByPenalties(); // orders the players by penalty minutes
        NHLStatistics.top(25);           // prints top 25
        
        System.out.println("");
        
        System.out.println("Statistics of Sidney Crosby");
        NHLStatistics.searchByPlayer("Sidney Crosby");  // prints stats of player
        
        System.out.println("");
        
        System.out.println("Statistics of the Philadelphia Flyers");
        NHLStatistics.teamStatistics("PHI");  // print stats of team
        
        System.out.println("");
        
        System.out.println("Players in Anaheim Duck ordered by points");
        NHLStatistics.sortByPoints();     // orders the players by points
        NHLStatistics.teamStatistics("ANA");
    }
}

Model Code

import nhlstats.NHLStatistics;

 

public class Main {

 

    public static void main(String[] args) {

        NHLStatistics.sortByGoals();

        NHLStatistics.top(10);

        NHLStatistics.sortByPenalties();

        NHLStatistics.top(25);

        NHLStatistics.searchByPlayer("Crosby");

        NHLStatistics.teamStatistics("PHI");

        NHLStatistics.sortByPoints();

        NHLStatistics.teamStatistics("ANA");

    }

}

As can be seen, my code is completely different to the model code. For starters I left import java.util.Scanner; in at the start which wasn’t needed at all along with Scanner reader = new Scanner(System.in);. This was a mistake.

The other differences aren’t so bad. I added comments, whitespace and titles to make the output more readable. If you look at the resulting statistics from mine;

Top ten by points
Alex Ovechkin          WSH        48 32 + 24= 56  36
Steven Stamkos         TBL        48 29 + 28= 57  32
John Tavares           NYI        48 28 + 19= 47  18
Jeff Carter            LAK        48 26 +  7= 33  16
Patrick Kane           CHI        47 23 + 32= 55   8
Jonathan Toews         CHI        47 23 + 25= 48  27
Jiri Tlusty            CAR        48 23 + 15= 38  18
Chris Kunitz           PIT        48 22 + 30= 52  39
Jakub Voracek          PHI        48 22 + 24= 46  35
Rick Nash              NYR        44 21 + 21= 42  26

Top twenty-five by penalties
Colton Orr             TOR        43  1 +  3=  4 155
Chris Neil             OTT        48  4 +  8= 12 144
Rich Clune             NSH        47  4 +  5=  9 113
B.J. Crombeen          TBL        44  1 +  7=  8 112
Brandon Prust          MTL        38  5 +  9= 14 110
Frazer McLaren         SJS, TOR   36  3 +  2=  5 102
Jared Boll             CBJ        43  2 +  4=  6 100
Steve Ott              BUF        48  9 + 15= 24  93
Ryane Clowe            SJS, NYR   40  3 + 16= 19  93
Antoine Roussel        DAL        39  7 +  7= 14  85
Zac Rinaldo            PHI        32  3 +  2=  5  85
Mark Fraser            TOR        45  0 +  8=  8  85
Cody McLeod            COL        48  8 +  4= 12  83
Wayne Simmonds         PHI        45 15 + 17= 32  82
Evander Kane           WPG        48 17 + 16= 33  80
Ryan Reaves            STL        43  4 +  2=  6  79
Mike Rupp              NYR, MIN   40  1 +  3=  4  79
David Clarkson         NJD        48 15 +  9= 24  78
Jordin Tootoo          DET        42  3 +  5=  8  78
Brandon Dubinsky       CBJ        29  2 + 18= 20  76
Tim Jackman            CGY        42  1 +  4=  5  76
Milan Lucic            BOS        46  7 + 20= 27  75
Matt Hendricks         WSH        48  5 +  3=  8  73
Corey Perry            ANA        44 15 + 21= 36  72
Scott Hartnell         PHI        32  8 +  3= 11  70

Statistics of Sidney Crosby
Sidney Crosby          PIT        36 15 + 41= 56  16

Statistics of the Philadelphia Flyers
Zac Rinaldo            PHI        32  3 +  2=  5  85
Wayne Simmonds         PHI        45 15 + 17= 32  82
Scott Hartnell         PHI        32  8 +  3= 11  70
Braydon Coburn         PHI        33  1 +  4=  5  41
Kimmo Timonen          PHI        45  5 + 24= 29  36
Jakub Voracek          PHI        48 22 + 24= 46  35
Luke Schenn            PHI        47  3 +  8= 11  34
Kurtis Foster          PHI        23  1 +  4=  5  25
Brayden Schenn         PHI        47  8 + 18= 26  24
Maxime Talbot          PHI        35  5 +  5= 10  23
Adam Hall              TBL, CAR, PHI 35  0 +  4=  4  23
Claude Giroux          PHI        48 13 + 35= 48  22
Nicklas Grossmann      PHI        30  1 +  3=  4  21
Mike Knuble            PHI        28  4 +  4=  8  20
Tye McGinn             PHI        18  3 +  2=  5  19
Ruslan Fedotenko       PHI        47  4 +  9= 13  12
Tom Sestito            PHI         7  2 +  0=  2  12
Danny Briere           PHI        34  6 + 10= 16  10
Sean Couturier         PHI        46  4 + 11= 15  10
Bruno Gervais          PHI        37  1 +  5=  6  10
Simon Gagne            LAK, PHI   38  5 + 11= 16   8
Matt Read              PHI        42 11 + 13= 24   2
Erik Gustafsson        PHI        27  3 +  5=  8   2
Scott Laughton         PHI         5  0 +  0=  0   0
Andrej Meszaros        PHI         4  0 +  0=  0   0
Eric Wellwood          PHI         4  0 +  0=  0   0

Players in Anaheim Duck ordered by points
Ryan Getzlaf           ANA        44 15 + 34= 49  41
Corey Perry            ANA        44 15 + 21= 36  72
Bobby Ryan             ANA        46 11 + 19= 30  17
Saku Koivu             ANA        47  8 + 19= 27  18
Teemu Selanne          ANA        46 12 + 12= 24  28
Francois Beauchemin    ANA        48  6 + 18= 24  22
Andrew Cogliano        ANA        48 13 + 10= 23   6
Kyle Palmieri          ANA        42 10 + 11= 21   9
Daniel Winnik          ANA        48  6 + 13= 19  16
Sheldon Souray         ANA        44  7 + 10= 17  52
Matt Beleskey          ANA        42  8 +  5= 13  56
Nick Bonino            ANA        27  5 +  8= 13   8
Cam Fowler             ANA        37  1 + 10= 11   4
Emerson Etem           ANA        38  3 +  7= 10   9
Ben Lovejoy            PIT, ANA   35  0 + 10= 10  29
Matthew Lombardi       PHX, ANA   28  4 +  4=  8   8
Luca Sbisa             ANA        41  1 +  7=  8  23
David Steckel          TOR, ANA   34  1 +  6=  7   4
Bryan Allen            ANA        41  0 +  6=  6  34
Toni Lydman            ANA        35  0 +  6=  6  12
Peter Holland          ANA        21  3 +  2=  5   4
Radek Dvorak           ANA         9  4 +  0=  4   2
Patrick Maroon         ANA         5  1 +  0=  1   0
Jordan Hendry          ANA         1  0 +  0=  0   0
Devante Smith-Pelly    ANA         3  0 +  0=  0   0
Rickard Rakell         ANA         4  0 +  0=  0   0
BUILD SUCCESSFUL (total time: 2 seconds)

…as opposed to the model solution. You can see why.

Alex Ovechkin          WSH        48 32 + 24= 56  36
Steven Stamkos         TBL        48 29 + 28= 57  32
John Tavares           NYI        48 28 + 19= 47  18
Jeff Carter            LAK        48 26 +  7= 33  16
Patrick Kane           CHI        47 23 + 32= 55   8
Jonathan Toews         CHI        47 23 + 25= 48  27
Jiri Tlusty            CAR        48 23 + 15= 38  18
Chris Kunitz           PIT        48 22 + 30= 52  39
Jakub Voracek          PHI        48 22 + 24= 46  35
Rick Nash              NYR        44 21 + 21= 42  26
Colton Orr             TOR        43  1 +  3=  4 155
Chris Neil             OTT        48  4 +  8= 12 144
Rich Clune             NSH        47  4 +  5=  9 113
B.J. Crombeen          TBL        44  1 +  7=  8 112
Brandon Prust          MTL        38  5 +  9= 14 110
Frazer McLaren         SJS, TOR   36  3 +  2=  5 102
Jared Boll             CBJ        43  2 +  4=  6 100
Steve Ott              BUF        48  9 + 15= 24  93
Ryane Clowe            SJS, NYR   40  3 + 16= 19  93
Antoine Roussel        DAL        39  7 +  7= 14  85
Zac Rinaldo            PHI        32  3 +  2=  5  85
Mark Fraser            TOR        45  0 +  8=  8  85
Cody McLeod            COL        48  8 +  4= 12  83
Wayne Simmonds         PHI        45 15 + 17= 32  82
Evander Kane           WPG        48 17 + 16= 33  80
Ryan Reaves            STL        43  4 +  2=  6  79
Mike Rupp              NYR, MIN   40  1 +  3=  4  79
David Clarkson         NJD        48 15 +  9= 24  78
Jordin Tootoo          DET        42  3 +  5=  8  78
Brandon Dubinsky       CBJ        29  2 + 18= 20  76
Tim Jackman            CGY        42  1 +  4=  5  76
Milan Lucic            BOS        46  7 + 20= 27  75
Matt Hendricks         WSH        48  5 +  3=  8  73
Corey Perry            ANA        44 15 + 21= 36  72
Scott Hartnell         PHI        32  8 +  3= 11  70
Sidney Crosby          PIT        36 15 + 41= 56  16
Zac Rinaldo            PHI        32  3 +  2=  5  85
Wayne Simmonds         PHI        45 15 + 17= 32  82
Scott Hartnell         PHI        32  8 +  3= 11  70
Braydon Coburn         PHI        33  1 +  4=  5  41
Kimmo Timonen          PHI        45  5 + 24= 29  36
Jakub Voracek          PHI        48 22 + 24= 46  35
Luke Schenn            PHI        47  3 +  8= 11  34
Kurtis Foster          PHI        23  1 +  4=  5  25
Brayden Schenn         PHI        47  8 + 18= 26  24
Maxime Talbot          PHI        35  5 +  5= 10  23
Adam Hall              TBL, CAR, PHI 35  0 +  4=  4  23
Claude Giroux          PHI        48 13 + 35= 48  22
Nicklas Grossmann      PHI        30  1 +  3=  4  21
Mike Knuble            PHI        28  4 +  4=  8  20
Tye McGinn             PHI        18  3 +  2=  5  19
Ruslan Fedotenko       PHI        47  4 +  9= 13  12
Tom Sestito            PHI         7  2 +  0=  2  12
Danny Briere           PHI        34  6 + 10= 16  10
Sean Couturier         PHI        46  4 + 11= 15  10
Bruno Gervais          PHI        37  1 +  5=  6  10
Simon Gagne            LAK, PHI   38  5 + 11= 16   8
Matt Read              PHI        42 11 + 13= 24   2
Erik Gustafsson        PHI        27  3 +  5=  8   2
Scott Laughton         PHI         5  0 +  0=  0   0
Andrej Meszaros        PHI         4  0 +  0=  0   0
Eric Wellwood          PHI         4  0 +  0=  0   0
Ryan Getzlaf           ANA        44 15 + 34= 49  41
Corey Perry            ANA        44 15 + 21= 36  72
Bobby Ryan             ANA        46 11 + 19= 30  17
Saku Koivu             ANA        47  8 + 19= 27  18
Teemu Selanne          ANA        46 12 + 12= 24  28
Francois Beauchemin    ANA        48  6 + 18= 24  22
Andrew Cogliano        ANA        48 13 + 10= 23   6
Kyle Palmieri          ANA        42 10 + 11= 21   9
Daniel Winnik          ANA        48  6 + 13= 19  16
Sheldon Souray         ANA        44  7 + 10= 17  52
Matt Beleskey          ANA        42  8 +  5= 13  56
Nick Bonino            ANA        27  5 +  8= 13   8
Cam Fowler             ANA        37  1 + 10= 11   4
Emerson Etem           ANA        38  3 +  7= 10   9
Ben Lovejoy            PIT, ANA   35  0 + 10= 10  29
Matthew Lombardi       PHX, ANA   28  4 +  4=  8   8
Luca Sbisa             ANA        41  1 +  7=  8  23
David Steckel          TOR, ANA   34  1 +  6=  7   4
Bryan Allen            ANA        41  0 +  6=  6  34
Toni Lydman            ANA        35  0 +  6=  6  12
Peter Holland          ANA        21  3 +  2=  5   4
Radek Dvorak           ANA         9  4 +  0=  4   2
Patrick Maroon         ANA         5  1 +  0=  1   0
Jordan Hendry          ANA         1  0 +  0=  0   0
Devante Smith-Pelly    ANA         3  0 +  0=  0   0
Rickard Rakell         ANA         4  0 +  0=  0   0
BUILD SUCCESSFUL (total time: 1 second)

Leave a comment