Intro to JAVA:
The Segment class describes a segment of the real line with a given start and end point. The class should implement the Moveable interface. To move a segment, its start and end points should be moved.
public class Segment {
private double start;
private double end;
/**
Constructs a linear segment.
@param from the starting point
@param to the ending point
*/
public Segment(double from, double to) {
start = from;
end = to;
}
public String toString() {
return start + "->" + end;
}
}
Moveable.java
/**
Describes any class whose objects can be moved.
*/
public interface Moveable {
/**
Moves this object by a given amount.
@param amount the amount by which to move the object
*/
void move(double amount);
}