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 4 of 4

Thread: Seeking help with a program.

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Seeking help with a program.

    I'm still fairly new to Java, I've made a few simple programs but nothing to advanced. I've just been assigned a project where I must make a program that makes graph for the 2 equations y = 600-sqrt(x) * 10 y = 300+300*sin(x/50.0). Normally this would not be an issue and getting the graph to show is not the problem. I realize I'll have to make 2 methods, one for each operation. The trick is I cannot use the Math.sqrt function and I have to use the binary search method. I guess I'm just looking for some guidance on the where to start exactly with the code for the method. Any input or advice is appreciated.


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Seeking help with a program.

    I'm not sure you'd have to make methods for the two functions - you'd end up calling them function1(double x) and function2(double x) or f(double x) and g(double x) or something equally not very helpful. If you're not allowed to use Math.sqrt then you'll certainly have to write a method for square root. Something like:
    public static double squareRoot(double x)
    and then implement the 'binary search method' whatever that is. Is it one of these methods?
    Methods of computing square roots - Wikipedia, the free encyclopedia

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Seeking help with a program.

    It looks like the high low method would work the best. Any suggestions or advice? Thank You for the help.

  4. #4
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Seeking help with a program.

    Binary search is used to find a value in a sorted list. I am not sure why you would need a binary search algorithm to plot two equations as a graph ... unless of course you have been asked to find where the two intersect then it would make a bit of twisted sense because you could push the results of the equations into two arrays and then search for equality for every value of the first against the second (basically a very long winded and problematic approach to solving simultaneous equations).

    As for not being allow to use Math.sqrt .. tough break. Your lecturer is obviously a bit of a sadist. Your best bet would be to look at the Babylonian_method. It translates better to pseudo-code than the high-low method (which is better for manual computation).

    Personally, to start this project I would clarify the question with your lecturer. Then as Sean4u stated, write a square root function and test it thoroughly. Next I would write a binary search function that accepts an array and a search value and returns the index of the position or -1.


    Hope that helps.

Similar Threads

  1. Seeking help with minesweeper style program.
    By Gravs2889 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 25th, 2012, 11:28 PM
  2. Beginner seeking help with quick problem in program
    By Gravs2889 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: February 23rd, 2012, 11:59 PM
  3. Replies: 6
    Last Post: February 21st, 2012, 09:41 PM
  4. NEW COMER SEEKING KNOWLEDGE AND GURUS
    By Abu Muhammad in forum Member Introductions
    Replies: 1
    Last Post: March 17th, 2011, 04:34 AM
  5. confused and seeking advice
    By mrgreaper in forum Java Theory & Questions
    Replies: 11
    Last Post: January 1st, 2011, 07:10 AM