Write a JAVA program to that uses method Your program should
Write a JAVA program to that uses method. Your program should have following methods: a. public static void main(String[] args) b. public static int readData(Scanner scan, double[] dArr, double SENT) this method reads data for your array dArr from the input file until sentinal value SENT is reached and returns the total number of elements in the array. c. public static double sumNumbers(double[] arr, int num) this method funds ths sum of all elements of arrary. Here num is the number of elements in the array and returns sum of all elements. Your input file should look like following: 0.7497790548868464 0.6462076498775827 0.32616335534841256 0.37582682849958304 -999.99 0.41621372481399 0.6463706270883212 0.7655177221930171 0.2650562905607654 0.14762994129539841 0.9627229328823885 -999.99 0.08133929860959621 0.9560335264804165 0.8155875415237163 -999.99 0.019074104888079813 0.8270564200270186 -999.99 You need to write a sentinel loop in main method where you call both methods and then you calculate the average of each group by dividing sum with total numbers read. In the readData method, you use another sentinel loop to read the values for each group. Here the sentinel loop in the main method makes sure that all the values are read and the sentinel loop in the readData method makes sure that the values for each group is read. ((USE ONLY (import java.util.Scanner;))) Your program should read this input file and should give your output like: The average of the group is 0.52. The average of the group is 0.53. The average of the group is 0.62. The average of the group is 0.42. The average overall inputs is 0.53.
Solution
ANS:
import java.util.Scanner;
class AvgDemo
{
public static double readData(Scanner sc, double[] dArr, double SENT)
{
double res,avg;
int res1=0,num=0;
for (int i = 0; i < SENT; i++)
{
System.out.println(\"Please enter number\");
dArr[i] = Double.parseDouble(sc.next());
}
num=dArr.length;
res=sumNumbers(dArr,num);
avg=res/SENT;
return avg;
}
public static double sumNumbers(double[] arr, int num)
{
double sum=0.0;
for(int i=0;i< num;i++)
{
sum=sum+arr[i];
}
return sum;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
double[] dArr = new double[100];
double SENT,f1;
System.out.println(\"please enter how many values for sent\");
SENT=Double.parseDouble(sc.next());
AvgDemo ad=new AvgDemo();
f1=ad.readData(sc,dArr,SENT);
System.out.println(\"The average of the group is = \"+f1);
}
}
![Write a JAVA program to that uses method. Your program should have following methods: a. public static void main(String[] args) b. public static int readData(S Write a JAVA program to that uses method. Your program should have following methods: a. public static void main(String[] args) b. public static int readData(S](/WebImages/6/write-a-java-program-to-that-uses-method-your-program-should-986463-1761506837-0.webp)