1
\$\begingroup\$

A newbie here. I have done this assignment that my university gave.

Requirements

  • Participants may enter the tournament as individuals or as part of a team**

  • It is expected that will be 4 teams each with 5 members and there will be 20 spaces for individual competitors

  • Each team or individual will complete 5 events

  • Each event will be defined as a team or individual event

  • The events will vary in type, from sporting to academic challenges

  • Individuals and teams will be awarded points according to their rank within each event

  • The points awarded for each event are as yet undecided and the college are willing to hear any suggestions you may have

  • Also the college would like to include the possibility of entering for one event only

I would like to know if my code is good enough or not. Or if there is more to be added and fixed.

When reviewing my program, kindly consider the following.

  • Suitability for audience and purpose of Scoring System
  • Meet criteria
  • Ease of Use
  • Quality of the software solution e.g. reliability, usability, efficiency/performance, maintainability,
  • constraints, , programmer knowledge
  • Strengths and weaknesses of my software
  • Improvements that can be made
  • Optimising software solutions, e.g. improving robustness, improving efficiency of the code, adding additional functionality

CODE

import java.util.Arrays;
import java.util.Scanner;

class ScoreSystem {


    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        // explanation of rules to the client to provide what the program is capable of
        System.out.println("Scoring System");
        System.out.println("\nScoring System Rules" + "\nNormal Scoring Rules\n" +
                "Rank 1 gives 20 points for Normal Teams and Participants");
        System.out.println("Rank 2 gives 10 points and Rank 3 gives 5 points");
        System.out.println("Rank 4 and lower will not receive any points\n");
        System.out.println("For Special Teams and Individuals");
        System.out.println("Rank 1 gives 100 points , Rank 2 Gives 80 points and Rank 3 Gives 60 points");
        System.out.println("Rank 4 or lower will not give any points");
        System.out.println("Constant Rules");
        System.out.println("5 Events are set for Normal Teams and Individuals");
        System.out.println("Only 1 event is allowed for Special Teams and Individuals ");
        System.out.println("There can only be 5 participants in both normal and special team\n");
        System.out.println("Common Rules");
        System.out.println("Normal Teams and Participants will participate in 5 events");
        System.out.println("Special Teams and Participants will participate in only 1 event");

// the start of teams
        // number of teams

        System.out.println("-----Teams------");
        System.out.println("Enter Amount of Teams Entering 5 EVENTS");
        int teamNo = scan.nextInt();

        String[] teamName = new String[teamNo];
        int[] teamScore = new int[teamNo];
        String[] Tevent = new String[5];
        String[] teamPart = new String[teamNo * 5];
        int teamRank;
        int eventNo = 5;
// condition check for number of teams
        // skip all of team code if 0

        if (teamNo == 0) {
        } else {
            // event names
            for (int i = 0; i < 5; i++) {
                System.out.println("Enter Event Name " + (i + 1) + " for the teams");
                Tevent[i] = scan.next();
            }
            for (int i = 0; i < teamNo; i++) {
                // participant names for the teams
                for (int a = 0; a < 5; a++) {
                    System.out.println("Enter Participant name " + (a + 1) + " for team " + (i + 1));
                    teamPart[i] = scan.next();
                }
            }

// name and rank of the teams

            for (int i = 0; i < teamNo; i++) {
                System.out.println("Enter Name of team " + (i + 1));
                teamName[i] = scan.next();

                for (int a = 0; a < eventNo; a++) {
                    System.out.println("Enter rank of the team on the event " + (a + 1));
                    teamRank = scan.nextInt();
                    int tRank = 0;
                    // scoring system for the teams
                    switch (teamRank) {
                        case 3:
                            tRank = 5;
                            break;
                        case 2:
                            tRank = 10;
                            break;
                        case 1:
                            tRank = 20;
                            break;
                    }
                    if (teamRank == 0 || teamRank >= 4) {
                        System.out.println("This team will not be awarded points");
                    } else {
                        teamScore[i] += tRank;
                        System.out.println(tRank + " points is granted for this event");
                    }

                    if (scan.hasNextLine()) {
                        scan.nextLine();
                    }
                }
            }
        }
// the start of individual participants
        // number of individuals

        System.out.println("-----Individuals-----");
        int PartNo;
        do {
            System.out.println("Enter the number of individuals participating 5 EVENTS" + " LIMITED SPACE OF 20");
            PartNo = scan.nextInt();
        } while (PartNo > 20);

        String[] PartName = new String[PartNo];
        int[] PartScore = new int[PartNo];
        String[] Pevent = new String[5];
        int PartRank;

// condition checking
        // skip all code for individual if 0

        if (PartNo == 0) {
        } else {
            // event name for the individuals
            System.out.println("Enter the 5 event names for participants ");
            for (int i = 0; i < 5; i++) {
                System.out.println("Enter Name of the event " + (i + 1) + " that the individuals are entering");
                Pevent[i] = scan.next();
            }
            // name and rank of the individuals
            for (int i = 0; i < PartNo; i++) {
                System.out.println("Enter name of Individual " + (i + 1));
                PartName[i] = scan.next();

                for (int a = 0; a < 5; a++) {
                    System.out.println("Enter rank of the individual on the event " + (a + 1));
                    PartRank = scan.nextInt();
                    int pRank = 0;
                    // start of scoring system for the individuals
                    switch (PartRank) {
                        case 3:
                            pRank = 5;
                            break;
                        case 2:
                            pRank = 10;
                            break;
                        case 1:
                            pRank = 20;
                            break;
                    }
                    if (PartRank == 0 || PartRank >= 4) {
                        System.out.println("This team will not be awarded points");
                    } else {
                        PartScore[i] += pRank;
                        System.out.println(pRank + " points is granted for this event");
                    }

                    if (scan.hasNextLine()) {
                        scan.nextLine();
                    }
                }
            }
        }
        System.out.println("Special Teams and Individuals Represent Teams and Individuals entering only 1 event");
        System.out.println(" If there are no Special Teams or Individuals Enter 0 when the amount is asked");

// the start of special teams
        // number of special teams

        System.out.println("-----Special_Teams-----");
        System.out.println("Enter Amount of Teams Entering only 1 EVENT");
        int SpecTeamNo = scan.nextInt();


        String[] SpecTeamName = new String[SpecTeamNo];
        String[] STevent = new String[1];
        int[] SpecTeamScore = new int[SpecTeamNo];
        String[] SteamPart = new String[(20 - PartNo) * 5];
        int sTeamRank;

// condition checking for number of special teams
        //skip if 0

        if (SpecTeamNo == 0) {
        } else {
            // event for special team
            for (int i = 0; i < 1; i++) {
                System.out.println("Enter Event Name " + (i + 1) + " for the teams");
                STevent[i] = scan.next();
            }
            // participant name for special team
            for (int a = 0; a < SpecTeamNo; a++) {
                for (int i = 0; i < 5; i++) {
                    System.out.println("Enter Participant name " + (i + 1) + " for team " + (a + 1));
                    SteamPart[i] = scan.next();
                }
            }

// name and rank of special teams

            for (int i = 0; i < SpecTeamNo; i++) {
                System.out.println("Enter Name of team " + (i + 1));
                SpecTeamName[i] = scan.next();

                for (int a = 0; a < 1; a++) {
                    System.out.println("Enter rank of the team on the event");
                    sTeamRank = scan.nextInt();
                    int stRank = 0;
                    // scoring system for special team
                    switch (sTeamRank) {
                        case 3:
                            stRank = 60;
                            break;
                        case 2:
                            stRank = 80;
                            break;
                        case 1:
                            stRank = 100;
                            break;
                    }
                    if (sTeamRank == 0 || sTeamRank >= 4) {
                        System.out.println("This team will not be awarded points");
                    } else {
                        SpecTeamScore[i] += stRank;
                        System.out.println(stRank + " points is granted for this event");
                    }

                    if (scan.hasNextLine()) {
                        scan.nextLine();
                    }
                }
            }
        }

// the start of special individuals
        // number of special individuals

        System.out.println("-----Special_Individuals-----");
        if (PartNo == 20) {
            System.out.println("No special individuals will be added as only 20 individuals are allowed");
        } else {
            int SpecPartNo;
            do {
                System.out.println("only 20 spaces are available for individuals and special individuals combined ");
                System.out.println("Please Enter Appropriate Amount of Participants");
                System.out.println("Enter Number of Individuals only Entering 1 event ");
                SpecPartNo = scan.nextInt();
            } while (SpecPartNo > 20 - PartNo);

            String[] SpecPartName = new String[SpecPartNo];
            String[] SPevent = new String[1];
            int[] SpecPartScore = new int[SpecPartNo];

//condition checking number of special individuals
            //skip all codes for special individuals if 0

            if (SpecPartNo == 0) {
            } else {
                // event for the special individuals
                for (int i = 0; i < 1; i++) {
                    System.out.println("Enter Event Name " + (i + 1) + " for the individuals");
                    SPevent[i] = scan.next();
                }

// name and rank input of special individuals

                for (int i = 0; i < SpecPartNo; i++) {
                    System.out.println("Enter Name of individual " + (i + 1));
                    SpecPartName[i] = scan.next();

                    for (int a = 0; a < 1; a++) {
                        System.out.println("Enter rank of the individual on the event");
                        int sPartRank = scan.nextInt();
                        int spRank = 0;
                        // scoring system for the individuals
                        switch (sPartRank) {
                            case 3:
                                spRank = 60;
                                break;
                            case 2:
                                spRank = 80;
                                break;
                            case 1:
                                spRank = 100;
                                break;
                        }
                        if (sPartRank == 0 || sPartRank >= 4) {
                            System.out.println("This individual will not be awarded points");
                        } else {
                            SpecPartScore[i] += spRank;
                            System.out.println(spRank + " points is granted for this event");
                        }

                        if (scan.hasNextLine()) {
                            scan.nextLine();
                        }
                    }
                }
            }


// output for all teams and individuals with their respective events and scores

            if (teamNo == 0) {
                System.out.println("There are no teams");
            } else {
                System.out.println("Amount of Teams: " + PartNo);
                System.out.println("Events Participated : 5");
                System.out.println("\t'Events List for Teams' : " + Arrays.asList(Tevent) + "\n");
                System.out.println("----------------------------------------------------------------------------");
                System.out.println("\tTeam\tParticipants");
                System.out.println("----------------------------------------------------------------------------");

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

                    System.out.println("| Team': " + teamName[i] + "\n" + "Participants " + teamPart[i] + "\n");
                    System.out.println("----------------------------------------------------------------------------\n");
                }
                System.out.println("Scores are shown respectively ");
                System.out.println("All Teams Scores : " + Arrays.toString(teamScore));
                System.out.println("----------------------------------------------------------------------------\n");
            }
            if (PartNo == 0) {
                System.out.println("There are no teams\n");
            } else {
                System.out.println("Amount of Participants: " + PartNo);
                System.out.println("Events Participated : 5");
                System.out.println("\t'Events List for Teams' : " + Arrays.asList(Pevent) + "\n");
                System.out.println("----------------------------------------------------------------------------");
                System.out.println("\t\tIndividual\nScore");
                System.out.println("----------------------------------------------------------------------------");
                for (int i = 0; i < PartNo; i++) {

                    System.out.println(" | \t'Individual Name': " + PartName[i]);

                }
                System.out.println("Scores are shown respectively ");
                System.out.println(" All Individual Scores:" + Arrays.toString(PartScore));
                System.out.println("----------------------------------------------------------------------------\n");
            }

            if (SpecTeamNo == 0) {
                System.out.println("There is no Special Teams");
            } else {
                System.out.println("Amount of Special Teams " + SpecTeamNo);
                System.out.println("Events Participated : 1");
                System.out.println("\t'Events List for Teams' : " + Arrays.asList(STevent) + "\n");
                System.out.println("----------------------------------------------------------------------------");
                System.out.println("\tSpecial Team\tParticipants\tScore");
                System.out.println("----------------------------------------------------------------------------");
                for (int i = 0; i < SpecTeamNo; i++) {

                    System.out.println("| \t'Special Team Name': " + SpecTeamName[i] + "\n" + "Special Team Participants " + SteamPart[i]);

                }
                System.out.println("Scores are shown respectively ");
                System.out.println("ALl Special Team Scores: " + Arrays.toString(SpecTeamScore));
                System.out.println("----------------------------------------------------------------------------\n");
            }
            if (PartNo == 20) {
                System.out.println("There are No Special Individuals");
            } else {
                if (SpecPartNo == 0) {
                    System.out.println("There are  no Special Individuals");
                } else {
                    System.out.println("Amount of Special Individuals " + SpecPartNo);
                    System.out.println("Events Participated : 1");
                    System.out.println("\t'Events List for Teams' : " + Arrays.asList(SPevent) + "\n");
                    System.out.println("----------------------------------------------------------------------------");
                    System.out.println("\tSpecial Individual\tScore");
                    System.out.println("----------------------------------------------------------------------------");
                    for (int i = 0; i < SpecPartNo; i++) {

                        System.out.println("| \t'Special Individual Name': " + SpecPartName[i]);

                    }
                    System.out.println("Scores are shown respectively ");
                    System.out.println("All Special Individuals Scores: " + Arrays.toString(SpecPartScore));
                    System.out.println("----------------------------------------------------------------------------\n");

                }
            }

        }
    }
}

I would like to know how the program is and if the output would be to your liking. And if there is anything else I should add.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

Java is an object-oriented language. If I were teaching a Java course and marking an assignment, one of the things I'd be looking at would be whether the student has applied object-oriented principles to their program.

As it's written, your code is entirely procedural with all the program logic in the main() method. main() should serve only as an entry point to your program, with the rest of the logic separated into classes and methods. I won't try to do the job of your professor by explaining OOP, but a starting point might be to look at the problem statements and list the noun phrases to identify the concepts you might want to represent as classes. This gives us:

  • Tournament
  • Event
  • Team
  • Individual (which you might refer to as Competitor)

Further analysis will give some clues about what methods these classes might contain or how they might be extended:

class Event {
  // The events will vary in type, from sporting to academic challenges
  EventType eventType;
}

enum EventType {
     ARCHERY, BOXING, SPELLING_BEE // ...
}

// Each event will be defined as a team or individual event
class TeamEvent extends Event {
    Map<Team, Integer> scores;
}

class IndividualEvent extends Event {
    Map<Competitor, Integer> scores;
}

Note that these are just some ideas, and there's no single correct way to implement these. I won't try to do your homework for you by implementing them fully.

You've also hard-coded the scoring system, meaning that if a user wanted to run a tournament that was scored differently they'd need to rewrite the code. Instead, consider a method of Tournament which looks at the Events played and the positions of each Team or Competitor in each, assigning points accordingly.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.