0
이 길이와 인수의 크기의 합과 크기가 같은 새로운 길이를 반환하는 add (Length) 메서드를 만들어야합니다. 나는 귀하의 요구 사항에 상황에 따라 다르다ADT에서 this에 인수 추가하기
public class Length implements Comparable<Length>{
private final double length; //private! Do NOT add a getter
// This constructor must remain private
private Length(double l){
length = l;
}
public double add(Length l){
return ;
}
public double subtract(Length l){
}
public double scale(double d){
}
public double divide(Length l){
}
public double Length(Position one, Position two){
}
// TODO: For all constants, have a line:
// public static final Length ... = new Length(...);
// Use the @Override annotation on all methods
// That override a superclass method.
@Override
public boolean equals(Object other){
//TODO
}
@Override
public int hashCode(){
//TODO
}
@Override
public String toString(){
//TODO
}
// If you are overriding a method from an interface, then Java 5
// says you CANNOT use Override, but Java 6 says you MAY. Either is OK.
// @Override
public int compareTo(Length other) {
//TODO
}
// TODO Write the rest of the methods for this class, and
// the other two classes.
}
'Length' 객체는 현재 'Length'와 인수로 전달 된 것과 같은 길이의 변수를 반환해야합니다. –
변경할 수없는 클래스를 만드시겠습니까? –