[jrauscher]$ javac RationalTest.java RationalTest.java:25: cannot find symbol symbol : class Fraction location: class RationalTest.RationalTest Fraction f1 = new Fraction(Num1, Den1); ^ RationalTest.java:25: cannot find symbol symbol : class Fraction location: class RationalTest.RationalTest Fraction f1 = new Fraction(Num1, Den1); ^ RationalTest.java:26: cannot find symbol symbol : class Fraction location: class RationalTest.RationalTest Fraction f2 = new Fraction(Num2, Den2); ^ RationalTest.java:26: cannot find symbol symbol : class Fraction location: class RationalTest.RationalTest Fraction f2 = new Fraction(Num2, Den2); ^ RationalTest.java:27: cannot find symbol symbol : class Fraction location: class RationalTest.RationalTest Fraction result = new Fraction(1,1); ^ RationalTest.java:27: cannot find symbol symbol : class Fraction location: class RationalTest.RationalTest Fraction result = new Fraction(1,1); ^ 6 errors
In my program for adding subtractin multiplying and dividing fractions the RationalTest.java file wont complie, the Fraction.java does complie
Any help would be appreciated thanks!
package rationaltest; import java.util.Scanner; public class RationalTest { public static void main (String args[]) { Scanner input = new Scanner(System.in); int Choice, Num1, Num2, Den1, Den2; System.out.printf("Enter numerator 1:"); Num1 = input.nextInt(); System.out.printf("Enter denominator 1:"); Den1 = input.nextInt(); System.out.printf("Enter numerator 2:"); Num2 = input.nextInt(); System.out.printf("Enter denominator 2:"); Den2 = input.nextInt(); Fraction f1 = new Fraction(Num1, Den1); Fraction f2 = new Fraction(Num2, Den2); Fraction result = new Fraction(1,1); char operation = ' '; System.out.printf("Enter precision:"); int Prec = input.nextInt(); do{ System.out.printf("\n1. Add\n2. Subtract\n3. Multiply\n4. Divide\n5. Exit\nChoice:"); Choice = input.nextInt(); switch (Choice) { case 1: operation = '+'; result = f1.Add(f2); break; case 2: operation = '-'; result = f1.Subtract(f2); break; case 3: operation = '*'; result = f1.Mult(f2); break; case 4: operation = '/'; result = f1.Div(f2); break; } System.out.printf("%s %c %s = %s (%s)\n",f1,operation,f2,result, result.asDecimal(Prec)); } while(Choice != 5); } }
package rationaltest; public class Fraction { private int Numerator; private int Denominator; public Fraction() { Numerator = 0; Denominator = 1; } public Fraction(int NumValue, int DenValue){ if (DenValue == 0){ System.out.println("!!Error: denominator Zero, a default rational 0/1 is stored instead."); Numerator = 0; Denominator = 1; } else { Numerator = NumValue; Denominator = DenValue; int divider = gcd(Numerator > 0 ? Numerator : -Numerator, Denominator > 0 ? Denominator : -Denominator); if (divider > 1) { Numerator /= divider; Denominator /= divider; } } } private static int gcd(int a,int b) { if (b==0) return a; return gcd(b,a%b); } public Fraction Add(Fraction x){ return new Fraction(this.Numerator*x.Denominator+x.Numerator*this.Denominator, this.Denominator*x.Denominator); } public Fraction Subtract(Fraction x) { return new Fraction(this.Numerator*x.Denominator - x.Numerator*this.Denominator, this.Denominator*x.Denominator); } public Fraction Mult(Fraction x) { return new Fraction(this.Numerator*x.Numerator,this.Denominator*x.Denominator); } public Fraction Div(Fraction x) { return new Fraction(this.Numerator*x.Denominator,x.Numerator*this.Denominator); } public String toString() { return String.format("%d/%d", this.Numerator, this.Denominator); } public String asDecimal(int Prec) { return String.format("%." + Prec + "f\n",(((double) getNum()) / ( (double) getDen()))); } public void setNum(int NumValue){ Numerator = NumValue; } public void setDen(int DenValue){ Denominator = DenValue; } public int getNum(){ return Numerator; } public int getDen(){ return Denominator; } }
Here are all the errors hope this helps