Hi, guys. I'm taking Intro to Java in college at the moment, and I'm supposed to be creating a program that will add, subtract, multiply, and divide two different fractions with two different constructors. I got it working just fine in Netbeans 7.2 (with the latest JDK), but for some reason, when I compile it in command prompt, I get quite a few "error: cannot find symbol" messages. To elaborate, they also include this:

"symbol: class Fraction

location: class TestFraction"

which I have read online elaborates on what parts are confusing the compiler. The errors are apparently surrounding my Fraction declarations (Fraction a, Fraction b, Fraction x, and Fraction y) at the beginning of my "TestFraction" code and every usage of those fractions in the rest of my code.

To be as thorough as possible, the Fraction code is supposed to be the two constructors and four math functions, while the TestFraction code is supposed to have two new Fractions to test whether the Constructors and all of the functions are working properly.

If the denizens of this forum could help me out, I would greatly appreciate it. I've been pulling my hair out over this thing for hours now, and it's probably going to be something obvious that I'm overlooking.

Here's the Fraction code first:

Now, the TestFraction code:Code:package fraction; public class Fraction { private int numerator; private int denominator; private int y; public Fraction () //This is the first constructor { numerator = 0; denominator = 1; } public Fraction(Fraction y) //This is the second constructor. { numerator = 9; denominator = 1; } public Fraction (int numerator, int denominator) { this.numerator = numerator; this.denominator = denominator; } public Fraction add(Fraction a) { int newNumerator = ((a.numerator*denominator) + (numerator*a.denominator)); int newDenominator = denominator*a.denominator; Fraction x = new Fraction (newNumerator, newDenominator); return x; } public Fraction subtract(Fraction a) { int newNumerator = ((numerator*a.denominator) - (a.numerator*denominator)); int newDenominator = denominator*a.denominator; Fraction x = new Fraction (newNumerator, newDenominator); return x; } public Fraction multiply(Fraction a) { int newNumerator = numerator*a.numerator; int newDenominator = denominator*a.denominator; Fraction x = new Fraction (newNumerator, newDenominator); return x; } public Fraction divide(Fraction a) { int newNumerator = numerator*a.denominator; int newDenominator = denominator*a.numerator; Fraction x = new Fraction (newNumerator, newDenominator); return x; } public void print() { System.out.println(this.numerator + "/" + this.denominator); } }

Code:package fraction; public class TestFraction { public static void main(String[] args) { Fraction a = new Fraction(3,1); Fraction b = new Fraction(7,4); Fraction x = new Fraction(); Fraction y = new Fraction(); System.out.println("Our two custom fractions are:"); a.print(); b.print(); //This is our test of our first constructor with the first fraction. System.out.println("Sum of a and First Constructor:"); x = new Fraction(); x = x.add(a); x.print(); System.out.println("Subtraction of a and First Constructor:"); x = new Fraction(); x = x.subtract(a); x.print(); System.out.println("Multiplication of a and First Constructor:"); x = new Fraction(); x = x.multiply(a); x.print(); System.out.println("Division of a and First Constructor:"); x = new Fraction(); x = x.divide(a); x.print(); //This is a test of the first constructor with our second fraction. System.out.println("Sum of b and First Constructor:"); x = new Fraction(); x = x.add(b); x.print(); System.out.println("Subtraction of b and First Constructor:"); x = new Fraction(); x = x.subtract(b); x.print(); System.out.println("Multiplication of b and First Constructor:"); x = new Fraction(); x = x.multiply(b); x.print(); System.out.println("Division of b and First Constructor:"); x = new Fraction(); x = x.divide(b); x.print(); //Here, we test the second constructor with our first fraction. System.out.println("Sum of a and Second Constructor:"); y = new Fraction (y); y = a.add(y); y.print(); System.out.println("Subtraction of a and Second Constructor:"); y = new Fraction (y); y = a.subtract(y); y.print(); System.out.println("Multiplication of a and Second Constructor:"); y = new Fraction (y); y = a.multiply(y); y.print(); System.out.println("Division of a and Second Constructor:"); y = new Fraction (y); y = a.divide(y); y.print(); //Now to test the Second Constructor with the second Fraction.) System.out.println("Addition of b and Second Constructor:"); y = new Fraction (y); y = b.add(y); y.print(); System.out.println("Subtraction of b and Second Constructor:"); y = new Fraction (y); y = b.subtract(y); y.print(); System.out.println("Multiplication of b and Second Constructor:"); y = new Fraction (y); y = a.multiply(y); y.print(); System.out.println("Division of b and Second Constructor:"); y = new Fraction (y); y = a.divide(y); y.print(); } }

Tweet This+ 1 thisPost To Linkedin