
Fraction class
Why wont this work ????
import java.util.*;
import java.io.*;
public class Fraction
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
Fraction num1 = new Fraction(2,10);
Fraction num2 = new Fraction(15,5);
Fraction num3 = new Fraction(24,18);
System.out.println(" " + num1);
System.out.println(" " + num2);
num3 = num1.add(num2);
System.out.println(" " + num3);
System.out.println("Addition = " + num1 + " + " + num2
+ " = " + num1.add(num2));
System.out.println("Multiplication = " + num1 + " * " + num2
+ " = " + num1.multiply(num2));
num3 = num1.subtract(num2);
System.out.println("Subtraction = " + num1 + "  " + num2
+ " = " + num1.subtract(num2));
System.out.println("Division = (" + num1 + ") / (" + num2
+ ") = " + num1.divide(num2));
}
}

What errors are you getting?
You're making a few Fraction objects. Do you have a class that has the Fraction constructor? The Fraction class looks like it should also have add(), subtract(), multiply() and divide() methods.

It would seem its the fractions themselves, the ones I have choosen there 9 errors.
Fraction.java:11: cannot find symbol
symbol : constructor Fraction(int,int)
location: class Fraction
Fraction num1 = new Fraction(2,10);
^
Fraction.java:12: cannot find symbol
symbol : constructor Fraction(int,int)
location: class Fraction
Fraction num2 = new Fraction(15,5);
^
Fraction.java:13: cannot find symbol
symbol : constructor Fraction(int,int)
location: class Fraction
Fraction num3 = new Fraction(24,18);
^
Fraction.java:18: cannot find symbol
symbol : method add(Fraction)
location: class Fraction
num3 = num1.add(num2);
^
Fraction.java:22: cannot find symbol
symbol : method add(Fraction)
location: class Fraction
+ " = " + num1.add(num2));
^
Fraction.java:24: cannot find symbol
symbol : method multiply(Fraction)
location: class Fraction
+ " = " + num1.multiply(num2));
^
Fraction.java:26: cannot find symbol
symbol : method subtract(Fraction)
location: class Fraction
num3 = num1.subtract(num2);
^
Fraction.java:30: cannot find symbol
symbol : method subtract(Fraction)
location: class Fraction
+ " = " + num1.subtract(num2));
^
Fraction.java:32: cannot find symbol
symbol : method divide(Fraction)
location: class Fraction
+ ") = " + num1.divide(num2));

As Masher said, you do not have a constructor defined for your Fraction class which takes two ints as arguments. That will take care of your first 3 errors. You need to define the multiply, subtract, divide, and add classes, which explains the other six errors.

you're right I redid it and came up with this , works fine now. Thanks for the feedback guys .
import java.util.*;
public class Fraction
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
Fraction num1 = new Fraction(3,4);
Fraction num2 = new Fraction(2, 10);
Fraction num3 = new Fraction(1, 8);
System.out.println("Fraction : " + num1);
System.out.println("Fraction : " + num2);
num3 = num1.add(num2);
System.out.println("Fraction : " + num3);
System.out.println("Addition = " + num1 + " + " + num2
+ " = " + num1.add(num2));
System.out.println("Multiplication = " + num1 + " * " + num2
+ " = " + num1.multiply(num2));
num3 = num1.subtract(num2);
System.out.println("Subtraction = " + num1 + "  " + num2
+ " = " + num1.subtract(num2));
System.out.println("Division = (" + num1 + ") / (" + num2
+ ") = " + num1.divide(num2));
}
}

So what did you change?
That code looks exactly the same....
Additionally, you should use the [ code ] tags

You've posted the old one
Please use:[code] put your code here
and after your code put :[]
inside the [] put /code.
Code:
import java.util.*;
public class Fraction
{}
Similar Threads

Replies: 27
Last Post: 02112016, 06:29 AM

By Osiris43 in forum .NET
Replies: 1
Last Post: 08042006, 12:15 PM

Replies: 5
Last Post: 01152006, 08:10 PM

By malehda3y in forum C++
Replies: 13
Last Post: 12032005, 03:35 PM

Replies: 5
Last Post: 10172002, 01:58 PM
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Development Centers
 Android Development Center
 Cloud Development Project Center
 HTML5 Development Center
 Windows Mobile Development Center
