Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Need some help

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need some help

    Hello, I'm new to the forums but thought this would be the best place to check. I'm taking a Java course in High School and we have programming projects that we take home to do. I had it all done but my computer was shut off and it didn't save. I also wasn't at school today to ask my teacher for help so I just wrote everything the best I could from memory. Here is the code I need help with. Its a drive class for a main class which is mean't to add, subtract, multiply, and divide two fractions that are supplied by the user.

    import java.util.Scanner;

    public class RationalDriver
    {
    public static void main(String [] args)
    {
    Scanner scan = new Scanner;
    int num1;
    int num2;
    int den1;
    int den2;

    System.out.println("Please enter the numerator of the first fraction: ");
    num1 = scan.nextInt();
    System.out.println("Please enter the denominator of the first fraction: ");
    den1 = scan.nextInt();
    System.out.println("Please enter the numerator of the second fraction: ");
    num2 = scan.nextInt();
    System.out.println("Please enter the denominator of the second fraction: ");
    den2 = scan.nextInt();

    Rational rat1 = new Rational (num1 , den1);
    Rational rat2 = new Rational (num2 , den2);

    Rational ratAdd = rat1.add(rat2);
    Rational ratSub = rat1.subtract(rat2);
    Rational ratMultiply = rat1.multiply(rat2);
    Rational ratDivide = rat1.divide(rat2);

    System.out.println("When your two fractions are added, they equal: "ratAdd);
    System.out.println("When your two fractions are subtracted, they equal: "ratSub);
    System.out.println("When your two fractions are multiplied, they equal: "ratMultiply);
    System.out.println("When your two fractions are divided, they equal: "ratDivided);

    }
    }
    The problem I am having is when I try to compile this code, the "Scanner scan = new Scanner;" is highlighted and I'm told that " '(' or '[' is expected." The thing is I don't know where I would be missing that at. Also if there any other problems you can see, please tell me as well.
    Last edited by BusyLiving10; January 6th, 2010 at 06:13 PM.

  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,097
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: Need some help

    See the API for Scanner (Java 2 Platform SE 5.0) (HINT: the first few paragraphs should address your problem)

  3. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some help

    i think this System.out.println("When your two fractions are added, they equal: "ratAdd); and the below should be System.out.println("When your two fractions are added, they equal: " + ratAdd);