Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can anyone help me with this java program? For this exercise, you will repeatedl

ID: 3865438 • Letter: C

Question

can anyone help me with this java program?

For this exercise, you will repeatedly read numbers from a text file. The numbers in the file represent daily rainfall amounts. The list may contain the number -999, which is an indicator that the end of the data we are interested in has been reached and you can stop reading the file.

The program will produce the average of the non-negative values in the list up to the -999 (if it shows up). There may be negative numbers other than -999 in the list.

The text file to be used with this application is attached: rainfall.txt

Explanation / Answer

RainfallAverage.java

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class RainfallAverage {

public static void main(String[] args) throws FileNotFoundException {

String fileName = "D: ainfall.txt";

File file = new File(fileName);

if(file.exists()) {

Scanner scan = new Scanner(file);

int value = scan.nextInt();

int total = 0;

int count = 0;

while(value!=-999) {

count++;

total+=value;

value = scan.nextInt();

}

double average = total/(double)count;

System.out.println("Average Rainfall: "+average);

} else {

System.out.println("File rainfall.txt does not exist");

}

}

}

Output:

Average Rainfall: 33.0

rainfall.txt

11
22
33
44
55
-999