Results 1 to 11 of 11
Thread: Cannot Find symbol error!
 02142012, 10:07 PM #1Member
 Join Date
 Nov 2011
 Posts
 15
 Rep Power
 0
Cannot Find symbol error!
In my program for adding subtractin multiplying and dividing fractions the RationalTest.java file wont complie, the Fraction.java does complie
I get the compile error in the RationalTest.java pointing at all the F's on these lines: 21,22,23
Any help would be appreciated thanks!
Java Code: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); } }
Java Code: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; } }
Last edited by Jtrtoday; 02142012 at 10:35 PM.
 02142012, 10:41 PM #2
Re: Cannot Find symbol error!
Delete any .class files that may be left over from a previous compile. Then recompile the classes.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
 02142012, 10:47 PM #3Member
 Join Date
 Nov 2011
 Posts
 15
 Rep Power
 0
Re: Cannot Find symbol error!
I deleted all my previous .class files and recomplied getting the same errors..
 02142012, 10:52 PM #4
Re: Cannot Find symbol error!
Copy and paste the errors here.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
 02142012, 10:55 PM #5Member
 Join Date
 Nov 2011
 Posts
 15
 Rep Power
 0
Re: Cannot Find symbol error!
Here are all the errors hope this helps
Plain Code:[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
Last edited by Jtrtoday; 02142012 at 11:06 PM.
 02142012, 11:05 PM #6
Re: Cannot Find symbol error!
Did you compile Fraction first?
Are the .java files in a folder named rationaltest?
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
 02142012, 11:07 PM #7Member
 Join Date
 Nov 2011
 Posts
 15
 Rep Power
 0
Re: Cannot Find symbol error!
Yes I compiled Fraction.java first, Even if i delete all the class files and recompile Fraction frist I still get same errors when compiling RationalTest.java
Last edited by Jtrtoday; 02142012 at 11:10 PM.
 02142012, 11:10 PM #8Member
 Join Date
 Nov 2011
 Posts
 15
 Rep Power
 0
Re: Cannot Find symbol error!
No their in a folder called Rational2
 02142012, 11:15 PM #9Member
 Join Date
 Nov 2011
 Posts
 15
 Rep Power
 0
Re: Cannot Find symbol error!
I moved the files to a new folder and named it RationalTest, and recomiplied with out sucuess im getting the same error.
 02152012, 12:58 AM #10
Re: Cannot Find symbol error!
Your package name is rationaltest, not RationalTest. The folder name has to match the package name and you have to compile from the package root: the folder that contains the rationaltest folder.
You need to go through this Lesson: Packages (The Java™ Tutorials > Learning the Java Language)
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
 02152012, 07:29 PM #11Member
 Join Date
 Nov 2011
 Posts
 15
 Rep Power
 0
Similar Threads

Cannot find symbol error
By cannonal in forum New To JavaReplies: 3Last Post: 01222012, 08:09 PM 
Cannot find symbol error?
By Josep_16 in forum New To JavaReplies: 2Last Post: 06192011, 07:14 PM 
Cannot find symbol error
By rajivjoshi in forum New To JavaReplies: 3Last Post: 05312010, 10:13 AM 
error cannot find symbol
By jcoon3 in forum New To JavaReplies: 3Last Post: 09272009, 10:56 PM 
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10182008, 08:26 PM
Bookmarks