I'm trying to solve a Data Structure programming Exercise, here is the problem requirements:
Farey Fraction of level one is defined as sequence (0/1,1/1), at level two , it is (0/1,1/2,1/1), at level three is (0/1,1/3,1/2,2/3,1/1)
at level four (0/1,1/4,1/3,1/2,2/3,3/4,1/1). So that at each level n, a new fraction a+b/c+d is inserted between two neighbor fractions a/c and b/d only if c + d <= n. write a program which for a number n entered by the user extends the linked list(sequence of terms) at level n and then display them?
Here is my implementation, I think I'm following the right logic but I have some warnings regarding the Object type I'm passing to the add () method from the LinkedList class
and the sequence class which contains the methods to add fraction objects to the sequence and allow the user to enter the number of level
and define the method that should insert the fraction in the sequence between two adjacent terms if they meet the condition c + d <= n
I would really appreciate if you can help me find the error in my code !!
I've edited your post by changing the 'javadoc' tags you used to 'code' tags so it displays properly on this forum.
Thanks a lot ,, it is my first post !!
Joined: Dec 20, 2012
Greg Charles wrote:Hi Mona, welcome to JavaRanch!
It would be helpful if you posted the warnings you are getting. They probably are related to a new(ish) concept in Java called generics. Try changing the class declaration to:
and see if that makes them go away.
here is the warning :
FractionSequence.java:17: cannot find symbol
symbol : class IndexOutOfBoundException
location: class FractionSequence
Note: FractionSequence.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Joined: Dec 20, 2012
Tony Docherty wrote:Your code contains IndexOutOfBoundException which should probably be IndexOutOfBoundsException
Actually, that first one is a compile error. The second one is a warning. The difference is that errors prevent you from getting .class files output from the compiler. Warnings mean the compiler isn't completely happy about it, but does compile your code into .class files.
In any case, Tony spotted the error and showed you how to fix it, and both of us guessed what the warning was, and I showed you how to fix that. You should be good to go, right?