In OOP, you should not be thinking in terms of "updating a record". You should *ask* an object to update *itself*. [aStream atEnd] whileFalse: [ |fields team1 team2 outcome| fields := aStream nextLine subStrings: ';'. team1 := self teamNamed: (fields at: 1). team2 := self teamNamed: (fields at: 2). outcome := fields at: 3. outcome = 'win' ifTrue: [team1 won. team2 lost]. outcome = 'draw' ifTrue: [team1 tied. team2 tied]. outcome = 'loss' ifTrue: [team1 lost. team2 won ]]. (Extracted from a working solution.) On Mon, 25 Mar 2019 at 19:29, Roelof Wobben <r.wobben@home.nl> wrote:
Thanks all
@Richard
I did tried that way in the solution I put on the net. But I get stuck at the point that if I update a record in the Team Class the collection at the Tournament class was not updated.
But right now , I try a new way to make it work that a new team is made and returned or a team is returned if that team is known.
Roelof
Op 25-3-2019 om 06:18 schreef Richard O'Keefe:
This is a simple programming-contest sort of exercise. You "need" only two classes. + a Team - knows its name (a String of at most 30 characters) * This should be passed when the Team is created; the rest of the program should NOT call (Team new) and should NEVER see an un#initialize-d Team instance. - knows the number of matches it has won, drawn, and lost (non-negative Integers, initially zero). - can report what it knows - can report the total match count and point score - can be told that it has won, drawn, or lost another match.
+ a Tournament - has a collection of Teams that it knows by name (a Dictionary) - and an sequence, initially undefined. - can read a set of match triples from a stream, forwarding the information about wins, draws, and losses to Team instances, which are created when a new name is found, - can convert the values of the teams collection to a sorted collection that is sorted by a somewhat vague order, I chose - descending on point score, then - descending on wins, then - ascending on losses, then - ascending on name. - can write the sorted teams to a stream in tabular form. ! Has a class method that does (self new) read: <<source>>; sort; write: <<destination>>
Frankly, formatting the output was the hardest part.
On Mon, 25 Mar 2019 at 10:00, Roelof Wobben <r.wobben@home.nl> wrote:
hello,
I think I have to reconsider my classes and reponsibilities
Right now Im thinking of this
Team : responsinble for team properties Ranking : reponsibilities for checking if a team is in the ranking and updating the team statics Tournament : parsing the ganes and call the right functions on Ranking
Can this work or am In making to much classes
Roelof
Op 24-3-2019 om 19:02 schreef Roelof Wobben:
Hello,
I tried another way to solve this but the code is a mess now.
I can update a record but the record is not updated. And I have to do a lot of the same steps for every team.
Anyone who can help me to get out of this mess.
Code so far: https://github.com/RoelofWobben/tournament
Roelof