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;
}
}