Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 3: Class Creation
Start Practice TestPractice Test
About Exam
hard

Point Midpoint

Mark
< Prev
Next >

A Coordinate class calculates a midpoint between two objects, returning a new instance.

What is printed when the following Java program is compiled and run?

public class QuestionTrace {

    public static void main(String[] args) {
        Coordinate p1 = new Coordinate(0, 0);
        Coordinate p2 = new Coordinate(10, 20);
        Coordinate p3 = p1.mid(p2);
        System.out.print(p3.getX() + "," + p3.getY());
    }
}

class Coordinate {

    private int x, y;

    public Coordinate(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public Coordinate mid(Coordinate other) {
        return new Coordinate((this.x + other.x) / 2, (this.y + other.y) / 2);
    }
}
A

10,20

B

0,0

C

5,5

D

5,10

Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|