1

Javaで有理数用にこのADTを構築しようとしていますが、何らかの理由で、コンパイルしようとするとシンボルが見つからないというエラーが発生し続けます。私は何を間違っていますか?このエラーは私の構文によるものですか?

Author: Juan Suarez
// Class : CS1102 ~ java
// Date  : 01/30/2018
// Topic : This porblem set focuse on the implemantation of an
//         ADT for rational numbers.

public class RationalC implements Rational {

private int num;
private int den;

// ****************** コンストラクタ **************************** *****

public RationalC (int numerator, int denominator) {
    if (this.den == 0){
        throw new ArithmeticException("*** WARNING! input non zero denominator");
    }
    int reduceFraction = gcd(numerator, denominator);
    this.num = numerator / reduceFraction;
    this.den = denominator / reduceFraction;

    if (this.den < 0) {
        this.den = this.den * -1;
        this.num = this.num * -1;
    }
}

//********************* ゲッター ************************** **********

public int getNumerator() { return this.num; }
public int getDenominator() { return this.den; }

public boolean equal(Rational b) {
  boolean
        a = this.getNumerator == b.getNumerator;
        v = this.getDenominator == b.getDenominator;

    return a && v;
}

// ******************* オペレーション **************************** ******

//return this + that
//
public RationalC plus(Rational b) {
    int commonDenominator = this.getDenominator() * b.getDenominator();
    int num1 = b.getDenominator() * this.getNumerator();
    int num2 = b.getNumerator() * this.getDenominator();
    int complete = num1 + num2;

    return new RationalC (complete, commonDenominator);
}
//returns this - that
//
public RationalC subtract(Rational b) {
    int commonDenominator = this.getDenominator() * b.getDenominator();
    int num1 = b.getDenominator() * this.getNumerator();
    int num2 = b.getNumerator() * this.getDenominator();
    int complete = num1 - num2;

    return new RationalC (complete, commonDenominator);

}
// return this * that
//
public Rational multiply(Rational b){
    int top = this.getNumerator() * b.getNumerator();
    int bottom = this.getDenominator() * b.getDenominator();

    return new RationalC (top, bottom);

}
//return this / that
//
public Rational divide(Rational b){
    int top = this.getNumerator() * b.getDenominator();
    int bottom = this.getDenominator() * b.getNumerator();

    return new RationalC (top, bottom);

}
//retuns value
//
public boolean equals(Rational b) {
    if (num == b.getNumerator() && this.getDenominator() == b.getDenominator() ) 
return(true);

    }

//********************* ツール ************************** ************

//returns the rational number to a string
//
    public String toString() {
        return "(" + this.num + "," + this.den + ")";

    }

//returns -1 , 0, +1 if the value of the rational is <, >, or =
//
    public int compareTo(Rational b) {
    long leftHand = this.getNumerator() * b.getDenominator();
    long rightHand = this.getDenominator() * b.getNumerator();
    if (leftHand < rightHand) return -1;
    if (leftHand > rightHand) return +1;
    return 0;
}
    private static int gcd(int m, int n) {
    if(m < 0) m = -m;
    if(n < 0) n = -n;
    return m * (n / gcd(m,n));

}
        public Rational reciprical(Rational b){
        return new RationalC (this.getDenominator(), this.getNumerator() );
    }

//******************** テストユニット ************************** *********

    public static void main(String[] args) {
        x = new Rational (1,2);
        y = new Rational (1,3);
        z = x.plus(y);
        StdOut.println(z);
    }
}
4

1 に答える 1