Hello again,
I've been trying this coding for weeks now and have no idea where the bug is.... Could someone help me? :mrgreen:

import javax.swing.joptionpane;
public class homework7{
public static void main(string args[]){

//prompt user to insert a value of signal array
String getsizearraystring = Joptionpane.showinputdialog(null,
"enter a value for the size of the array:","Homework7",
Joptionpane.question_message);

int getsizearray = integer.parseInt(getsizearrayString);

//declare
int[] getsignal = new int [getsizearray];

getsignal = getsignal(getsizearray);

int[]getsmoothsignal = smooth (getsizearray.getsignal);

//display output
Joptionpane.showinputmessagedialog(null,
showoutput(getsizearray,getsignal,getsmoothsignal)+"complete\n",
"homework7",Joptionpane.information_message);

System.exit(0);
}

//return get array value method
public static int[] getsignal(int s){

//declare
int[] getnumber = new int [s];

//prompt user to insert values of the array
for(int index = 0; index < s; index++){

String getintstring = joptionpane.showinputdialog(null,
"enter value of array:","homework7",
Joptionpane.question_message);

getnumber[index]=integer.parseInt(getIntstring);

//error message is shown if the user value that are less than 2
while (getnumber[index]<2){

Joptionpane.showmessagedialog(null,
"there is an error \n" + "Please re-insert your values","homework7",
Joptionpane.error_message);

getIntString = Joptionpane.showinputdialog(null,
"Enter values of array:","Homework7",Joptionpane.question_message);

getnumber[index] = integer.parseInt(getIntString);
}
}
return get number;
}
//return calculation
public static int[]smooth(int a, int[] signalss)
{

//declare
int[]smooth = new int [a];

//calculate the values of 1st element
smooth[0]=(signals[0]+signals[1])/2;

//calculate the values of middle element
for (int i = 1; i <= a - 2; i++)
{
smooths=(signals[i-1]+signals+signals[i+1])/3;

}
//calculate the last element
int endValue = a - 1;
smooths[endvalue]=(signals[endvalue-1]+signals[endvalue])/2;

return smooths;
}

//return the output message
public static string showOutput(int a, int[]signal,int[]smooth)
{

String output = "signal"+" "+smooth\n";
for (int index = 0; index < a; index++)
{
output += signal[index]+" "+" " +smooth[index]+"\n";
}
return output;
}
}

Recommended Answers

All 3 Replies

Dear friend

next time when posting please use tag code which is under symbol #, its make it easier to read the code. Thank you.
To your code. I took time to check it after initiatial 3 errors which I sorted come another 38. All this errors are related to your un-standart code writing. When documentation say

import javax.swimg.JOptionPane;

it is not same as yours

import javax.swing.joptionpane;

Java is not benevolent HTML where capital and lower letters can be mixed up as you wish. So please check all your coding for these mistakes and corect it and post it again if you get into troubles

Bellow you find the first correction which I made after first compile

import javax.swing.joptionpane;
public class homework7
{
	public static void main(string args[])
	{	
		//prompt user to insert a value of signal array
		String getsizearraystring = Joptionpane.showinputdialog(null,
		"enter a value for the size of the array:","Homework7",
		Joptionpane.question_message);
		
		int getsizearray = integer.parseInt(getsizearrayString);
		
		//declare
		int[] getsignal = new int [getsizearray];
		
		getsignal = getsignal(getsizearray);
		
		int[]getsmoothsignal = smooth (getsizearray.getsignal);
		
		//display output
		Joptionpane.showinputmessagedialog(null,
		showoutput(getsizearray,getsignal,getsmoothsignal)+"complete\n",
		"homework7",Joptionpane.information_message);
		
		System.exit(0);
	}
		
	//return get array value method
	public static int[] getsignal(int s)
	{		
		//declare
		int[] getnumber = new int [s];
		
		//prompt user to insert values of the array
		for(int index = 0; index < s; index++)
		{		
			String getintstring = joptionpane.showinputdialog(null,
			"enter value of array:","homework7",
			Joptionpane.question_message);
			
			getnumber[index]=integer.parseInt(getIntstring);
			
			//error message is shown if the user value that are less than 2
			while (getnumber[index]<2)
			{		
				Joptionpane.showmessagedialog(null,
				"there is an error \n" + "Please re-insert your values","homework7",
				Joptionpane.error_message);
				
				getIntString = Joptionpane.showinputdialog(null,
				"Enter values of array:","Homework7",Joptionpane.question_message);
				
				getnumber[index] = integer.parseInt(getIntString);
			}
		}
		return getnumber; [B]// you had as get number in 2 words[/B]
	}
	//return calculation
	public static int[]smooth(int a, int[] signalss)
	{
		
		//declare
		int[]smooth = new int [a];
		
		//calculate the values of 1st element
		smooth[0]=(signals[0]+signals[1])/2;
		
		//calculate the values of middle element
		for (int i = 1; i <= a - 2; i++)
		{
			smooths[i]=(signals[i-1]+signals[i]+signals[i+1])/3;		
		}
		//calculate the last element
		int endValue = a - 1;
		smooths[endvalue]=(signals[endvalue-1]+signals[endvalue])/2;
		
		return smooths;
	}
		
	//return the output message
	public static string showOutput(int a, int[]signal,int[]smooth)
	{
		
		String output = "signal"+" "+smooth +"\n"; [B]// missing plus and quotation sign " after smooth[/B]
		for (int index = 0; index < a; index++)
		{
			output += signal[index]+" "+" " +smooth[index]+"\n";
		}
		return output;
	}
}

And split your code into several classes.
The signal processing code is completely independent from the user interface and should not be a part of the user interface code.

Check Sun's website for the Java code conventions to learn how to properly name classes, methods, and variables (as well as other code layout issues).
Adhering to that isn't mandatory for the compiler to work but is mandatory in most companies using Java and designed to make your code a lot easier to read (and thus understand).

Thanks guyz... I am still a noob in Java World:!:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.