dMw Chit Chat => The Beer Bar => Seriously though ... => Topic started by: A Twig on March 15, 2007, 11:44:23 AM
Title: JAVA Fourier Synthesis Program - Compile Problems
Post by: A Twig on March 15, 2007, 11:44:23 AM
This program I've written won't compile - according to my tutor its something really obvious. I've spent hours on the bloody thing - any ideas anyone?
Basically you input the parameters, and the program computes the resulting waveform values into an array that can be plotted.
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class FourierInput {
public static void main(String[] args) throws IOException { InputStreamReader reader = new InputStreamReader(System.in); BufferedReader console = new BufferedReader(reader); System.out.println("Choose case to be run (1-5):"); String input = console.readLine(); int Case = Integer.parseInt(input);
System.out.println("Choose an integer number of intervals (t):"); String input2 = console.readLine(); double time = Double.parseDouble(input2);
Solution = new double[(int)time]; AnArray = new double[(int)time]; BnArray = new double[(int)time];
double[] TimeArray; TimeArray = new double[(int)time]; for(r=0; r
Title: JAVA Fourier Synthesis Program - Compile Problems
Post by: Jamoe on March 15, 2007, 11:57:48 AM
One of the guys at work does a lot of Java so I've sent him an email, if hes got time he will likely take a look.
Title: JAVA Fourier Synthesis Program - Compile Problems
Post by: Bob on March 15, 2007, 12:06:21 PM
You have a ton of compilation errors in that one Twig. It is too many for me to explain 'em all, but here is a screen shot from eclipse where you can see 'em all:
As a couple of examples: The "r cannot be resolved" is due to you have written the for-statement wrong - it should look like this: for(int r=0; r
Title: JAVA Fourier Synthesis Program - Compile Problems
Post by: spiritus on March 15, 2007, 12:12:14 PM
i'm with bob here. had a little look at it. and i don't have netbeans here. was a biig code to read. and netbeans are freeware if i remember correctly. had to use textpad also. that sucks. but here you go: http://www.netbeans.org/ enjoy :D
edit: didn't see bobs links.. bah. bob rocks!
Title: JAVA Fourier Synthesis Program - Compile Problems
Post by: A Twig on March 15, 2007, 01:27:08 PM
Yeah, I've been using BlueJ which seems a bit poo to be honest. Cheers for the pointers - proof that large amounts of bourbon and JAVA don't mix...
Title: JAVA Fourier Synthesis Program - Compile Problems
Post by: A Twig on March 15, 2007, 01:39:39 PM
Ok, I've cleared it up, but having difficulties sending my Arrays to the function. It said error "found double, expected double[]" and so I whacked in the square brackets, and now it says ".class expected"
I reckon I'm defining something wrong, again its probably a really obvious thing, but JAVA really isn't my strong point. Neither's maths. In fact come to think of it my whole degree isn't really my strong point....
for ( int q=0; q<(time); q++) { for ( int c=0;c<(q); c++) { Calc=(Calc + (AnArray[c]*Math.cos(time*omega*TArray[c])));} Solution[q]=(AnArray[0] + Calc);}
Title: JAVA Fourier Synthesis Program - Compile Problems
Post by: Jamoe on March 15, 2007, 02:10:03 PM
The only thing i have noticed is that you declare the function Fourier to return a double but that function isn't actually returning anything. Its been along time since I did any java but is that going to cause a problem.
/* Initialize the arrays with the values they should hold */
Solution = Fourier(time, anArray, bnArray, interval, T); And also as Jamoe said, the function Fourier must return a double!
Sorry to be a pina, I've done that, my Fourier function now returns the double array (can I do that?) The AnArray and BnArray are defined in each case from the switch statement.
Writing it as you've put it there gives me "incompatible types - found double, expected double[]" error when compiling.
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class FourierInput {
public static void main(String[] args) throws IOException { InputStreamReader reader = new InputStreamReader(System.in); BufferedReader console = new BufferedReader(reader); System.out.println("Choose case to be run (1-5):"); String input = console.readLine(); int Case = Integer.parseInt(input);
System.out.println("Choose an integer number of intervals (t):"); String input2 = console.readLine(); double time = Double.parseDouble(input2);
public static double[] Fourier(double time, double[] AnArray, double[] BnArray, double interval, double T)Notice the square brackets after public static double[] which are needed since you are returning an array of double.
public static double[] Fourier(double time, double[] AnArray, double[] BnArray, double interval, double T){ double interval= ((3*T)/time);This will give you a Duplicate local variable interval error. Either you must remove double before interval= ((3*T)/time) if your intention is to use the variable which are passed to the function, or you need to choose another name for it.
You will also still have the error that Solution cannot be resolved inside the Fourier function, as you haven't declared this array in here.
Title: JAVA Fourier Synthesis Program - Compile Problems
Post by: A Twig on March 15, 2007, 03:28:32 PM
Brilliant, cheers mate. You're an absolute lifesaver. Just reckon there's something wrong with my maths bit somewhere, cos my entire solution array is zero :eyebrow:
Reckon that should just be a pretty simple tweak tho, thanks again, send me your address and I'll post you a beer!
EDIT: Had forgotten the second half of the Fourier function. It's still not quite right, but it'll definitely get me a pass at least now!
EDIT EDIT: All fixed :D
Title: JAVA Fourier Synthesis Program - Compile Problems
Post by: Bob on March 15, 2007, 03:43:42 PM
Glad I could be of any help :)
But I think I'll pass on that beer - don't think it'll be too god after passing through the postal service... But I'll remember it for dMw lan XII if you should show up there :cheers: