Point Midpoint
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
Question Leaderboard
Not enough data yet to show leaderboard.
