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

# Thread: Seeking help with a program.

1. ## 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. ## 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. ## 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. ## 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.