0

私のプログラムは四辺形を作成しています.findArea()とfindPerimeter()の抽象メソッドを作成するように言われましたが、toString()とboolean equalsメソッドに必要ですか?

abstract public class Quad {
private int s; //Base top
public Quad(){
    s = 1;
}
Quad(int s){
    this.s = s;
}
abstract public int findPerimeter();
abstract public int findArea();
abstract public String toString();
abstract public boolean equals(Object o);
public int getS() {
    return s;
}
public void setS(int s){
    this.s = s;
}

}

class Square extends Quad{
private static int numSquares = 0;
private int s, iD;
public Square(){
    super();
    s = super.getS();
    numSquares ++;
    iD = numSquares;
}
public Square(int s){
    super(s);
    s = super.getS();
    numSquares ++;
    iD = numSquares;
}
public int getNumSquares(){
    return numSquares;
}
public int getID(){
    return iD;
}
public void setID(int iD){
    this.iD = iD;
}
@Override
public int findArea(){
    return (getS()*getS());
}
@Override
public int findPerimeter() {
    return (getS())*4; 
}
public String toString(){
    return "Side length is "+getS()+", Area is "+findArea()+" and Perimeter is "+findPerimeter();
}
public void decreaseNum(){
    numSquares --;
}
public boolean equals(Object s){
    if (s instanceof Square){
        Square temp = (Square)s;
        if(getID() == (temp.getID())){
            return true;
        }
    }
    return false;
}

}

これがコードです。読んで助けてくれてありがとう!

4

1 に答える 1