Kotlinlearncs.online LogoJava
Return to List

Homework: Score Tracker

Created By: Geoffrey Challen
/ Version: 2021.9.0

Create a public class named ScoreTracker that we'll use to keep track of the scores of two players who are playing a game. Players playing this game always take turns, and Player 1 always plays first. Both players scores start at zero.

Each ScoreTracker should provide a public method score that accepts a number of points and does not return a value. If it is Player 1's turn, the points (which might be negative) get added to their score. Otherwise they get added to Player 2's score.

You should also provide a public method currentlyAhead that returns 1 if Player 1 is ahead, 2 if Player 2 is ahead, and 0 if it's a tie.

You should not expose any of your state publicly, and ScoreTracker does not need to provide a public constructor.

When your class is complete, here is how it should work:

Related Lessons

Stuck? You may find these lessons helpful: