AP CSA 3.2 Exercise 1: Scoreboard Interface

Unit 3: Class Creation · Lesson 3.2 · Exercise 1

Scoreboard Interface

Impact of Program Design. Write real Java, run it, and submit it to be graded against hidden test cases.

Why this one is worth doing

What a method returns is a design decision with consequences. leader returns a NAME and margin returns a NUMBER, and a caller that only had the raw scores would have to work both out for itself every time.

What to write

  1. Write a class named Scoreboard that tracks two team names and their scores. Both scores start at zero.
  2. scoreHome and scoreAway add points to the right team.
  3. getHomeScore and getAwayScore return the current scores.
  4. leader returns the name of the team that is ahead, or the exact word TIE when the scores are equal.
  5. margin returns how far ahead the leader is, which is never negative.

Your program reads

The grader supplies the input. Your class does not read anything.

Your program prints

Your class prints nothing. The grader prints what your methods return.

The class the grader will call

Your answer must declare exactly these, spelled exactly like this. The grader creates the object and calls the methods itself, so a method under a different name is a method it cannot find.

class Scoreboard
Scoreboard(String homeName, String awayName)
void scoreHome(int points)
void scoreAway(int points)
int getHomeScore()
int getAwayScore()
String leader()
int margin()

Do not write a class named Main and do not write a main method. The grader supplies its own.

Worked examples

These are the cases you can see. There are more you cannot, and they use different values, so an answer that prints these numbers as constants will fail.

Example 1 input
Lions Bears
3
1 7
2 3
1 3
Example 1 output
TIE
10
3
Lions
7
Example 2 input
Reds Blues
0
Example 2 output
TIE
0
0
TIE
0

Your answer

Main.java

Input for the Run button

Run uses the sample main shown below, which is not the one that grades you. Submitting runs your class against the real cases, including hidden ones.

The sample main the Run button uses
public class Main {
  public static void main(String[] args) {
    Scoreboard board = new Scoreboard("Lions", "Bears");
    board.scoreHome(7);
    board.scoreAway(3);
    System.out.println(board.leader());
    System.out.println(board.margin());
  }
}


  

  

Stuck?

Hint 1

A brand new Scoreboard has both scores at zero, so leader() has to answer TIE before anybody has scored.

Hint 2

margin is never negative. Math.abs on the difference handles both directions in one expression.

Hint 3

Return the stored name, not a copy you typed out. The team names come from whoever built the object.

Where to go next

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]