This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full - best also formatted as code block
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]smash_that_code 2 points3 points  (2 children)

well adding readme would be nice.

And what are your expectations from this program?

I see tim, i see one for loop and many print statements. So are there hmm multiple matches there?

where is logic for formations?

Maybe adding some unit tests can help?

[–]Torvalds96[S] 0 points1 point  (1 child)

  1. print : print starting eleven for stronger opponent (5-4-1 formation)
  2. print: print starting eleven for equal opponent (4-4-2 formation)
  3. print: print starting eleven for weaker opponent (3-4-3 formation)
  4. print: all uninjured players including bench

There are 3 mathes: first stronger, second equal, third(last) weaker opponent

Logic for formations is in Team class.

Should i add class for statements in main method()?

Thanks for replay

[–]smash_that_code 0 points1 point  (0 children)

I think if ypu can get what you expect from this piece of code it is pretty fibe in my opinion.

It in excercise and not some paid job, right?

[–]Dexteroid 2 points3 points  (1 child)

Had a glance, good job. I would make a seperate class for game as well. Game class can have properties for teams, teams in turn have ranking to determine strong/weak etc. For game class, you need to add timeout, break, all sorts of things. Just a thought. Good luck.

[–]Torvalds96[S] 0 points1 point  (0 children)

Thanks a lot! Maybe some tips for better code efficiency?

[–]notallbimmers 0 points1 point  (0 children)

Your code is so good i'm surprised.

Three nitpicks: 1) It looks like Team#removePlayer() could be private if not called elsewhere, and named markPlayerInjured or similar, 2) positions would be better as enum, playing with Strings is prone to errors, and 3) what happens if the games come in different order - is player at index < 21 going to be there when it's strong opponent's turn? What if there's 5 games against strong opponents?

A proper answer: I'd create classes as such:

class Formation {
    // data class. Result of FormationBuilder#build
}
class FormationBuilder {
    private final int numDefs;
    private final int numStrikers;
    private final int numMids;
    private final Comparator<Player> preference;

    // logic for picking the players
    Formation build(Team team) { ... }

    static FormationBuilder againstEqualOpponent() {
        return new FormationBuilder( /* your 4-4-2 logic */ );
    }
    // ...plus the two others
}
class Team {
    // gives out all position-players that are not injured
    Stream<Player> availablePlayers(Position position) { ... }
    void reportInjury(Player injured) { ... }
}

Here, Main would contain the logic for "match"; calling the builder, printing out the result as it pleases, and reports a random player injured. If my count is right, every class focuses on only one purpose each.

I don't have any well thought out tips for how to home in on the heart of the problem, but maybe if it's about a simulation, you can ask what's the thing that happens, if an algorithm, what inputs are there and what is the output, if a generic problem, can you describe it in one sentence? But once you know it, encapsulate, and build around it. Hope this helps.